Skip to content

Commit cf16f63

Browse files
committed
Fix code style
1 parent ce65c06 commit cf16f63

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

src/DocBlock/Tags/InvalidTag.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
use ReflectionClass;
1010
use ReflectionFunction;
1111
use Throwable;
12+
use function array_map;
13+
use function array_walk_recursive;
14+
use function get_class;
15+
use function get_resource_type;
16+
use function is_object;
17+
use function is_resource;
18+
use function sprintf;
1219

1320
/**
1421
* This class represents an exception during the tag creation
@@ -77,32 +84,35 @@ private function flattenExceptionBacktrace(Throwable $exception) : void
7784
$traceProperty = (new ReflectionClass('Exception'))->getProperty('trace');
7885
$traceProperty->setAccessible(true);
7986

80-
$flatten = static function (&$value) {
81-
if ($value instanceof Closure) {
82-
$closureReflection = new ReflectionFunction($value);
83-
$value = sprintf(
84-
'(Closure at %s:%s)',
85-
$closureReflection->getFileName(),
86-
$closureReflection->getStartLine()
87-
);
88-
} elseif (is_object($value)) {
89-
$value = sprintf('object(%s)', get_class($value));
90-
} elseif (is_resource($value)) {
91-
$value = sprintf('resource(%s)', get_resource_type($value));
92-
}
93-
};
87+
$flatten =
88+
/** @param mixed $value */
89+
static function (&$value) : void {
90+
if ($value instanceof Closure) {
91+
$closureReflection = new ReflectionFunction($value);
92+
$value = sprintf(
93+
'(Closure at %s:%s)',
94+
$closureReflection->getFileName(),
95+
$closureReflection->getStartLine()
96+
);
97+
} elseif (is_object($value)) {
98+
$value = sprintf('object(%s)', get_class($value));
99+
} elseif (is_resource($value)) {
100+
$value = sprintf('resource(%s)', get_resource_type($value));
101+
}
102+
};
94103

95104
do {
96105
$trace = array_map(
97-
static function($call) use ($flatten) {
106+
static function (array $call) use ($flatten) : array {
98107
array_walk_recursive($call['args'], $flatten);
99108

100109
return $call;
101110
},
102111
$exception->getTrace()
103112
);
104113
$traceProperty->setValue($exception, $trace);
105-
} while ($exception = $exception->getPrevious());
114+
$exception = $exception->getPrevious();
115+
} while ($exception !== null);
106116

107117
$traceProperty->setAccessible(false);
108118
}

tests/unit/DocBlock/Tags/InvalidTagTest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
use Exception;
88
use InvalidArgumentException;
99
use PHPUnit\Framework\TestCase;
10+
use Throwable;
11+
use function fopen;
12+
use function serialize;
13+
use function unserialize;
1014

1115
/**
1216
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\InvalidTag
@@ -38,17 +42,17 @@ public function testCreationWithError() : void
3842

3943
self::assertSame('name', $tag->getName());
4044
self::assertSame('@name Body', $tag->render());
41-
self::assertSame('Body', (string)$tag);
45+
self::assertSame('Body', (string) $tag);
4246
self::assertSame($exception, $tag->getException());
4347
}
4448

4549
public function testCreationWithErrorContainingClosure() : void
4650
{
4751
try {
4852
$this->throwExceptionFromClosureWithClosureArgument();
49-
} catch (Exception $e) {
53+
} catch (Throwable $e) {
5054
$parentException = new Exception('test', 0, $e);
51-
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
55+
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
5256
self::assertSame('name', $tag->getName());
5357
self::assertSame('@name Body', $tag->render());
5458
self::assertSame($parentException, $tag->getException());
@@ -58,36 +62,36 @@ public function testCreationWithErrorContainingClosure() : void
5862
}
5963
}
6064

61-
private function throwExceptionFromClosureWithClosureArgument()
65+
private function throwExceptionFromClosureWithClosureArgument() : void
6266
{
63-
$function = function() {
67+
$function = static function () : void {
6468
throw new InvalidArgumentException();
6569
};
6670

6771
$function($function);
6872
}
6973

70-
public function testCreationWithErrorContainingResource()
74+
public function testCreationWithErrorContainingResource() : void
7175
{
7276
try {
7377
$this->throwExceptionWithResourceArgument();
74-
} catch (Exception $e) {
78+
} catch (Throwable $e) {
7579
$parentException = new Exception('test', 0, $e);
76-
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
80+
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
7781
self::assertSame('name', $tag->getName());
7882
self::assertSame('@name Body', $tag->render());
7983
self::assertSame($parentException, $tag->getException());
8084
self::assertStringStartsWith(
8185
'resource(stream)',
82-
$tag->getException()->getPrevious()->getTrace()[0]['args'][0])
83-
;
86+
$tag->getException()->getPrevious()->getTrace()[0]['args'][0]
87+
);
8488
self::assertEquals($parentException, unserialize(serialize($parentException)));
8589
}
8690
}
8791

88-
private function throwExceptionWithResourceArgument()
92+
private function throwExceptionWithResourceArgument() : void
8993
{
90-
$function = function() {
94+
$function = static function () : void {
9195
throw new InvalidArgumentException();
9296
};
9397

0 commit comments

Comments
 (0)