mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Fix code style
This commit is contained in:
@@ -9,6 +9,13 @@ use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use ReflectionClass;
|
||||
use ReflectionFunction;
|
||||
use Throwable;
|
||||
use function array_map;
|
||||
use function array_walk_recursive;
|
||||
use function get_class;
|
||||
use function get_resource_type;
|
||||
use function is_object;
|
||||
use function is_resource;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* This class represents an exception during the tag creation
|
||||
@@ -77,24 +84,26 @@ final class InvalidTag implements Tag
|
||||
$traceProperty = (new ReflectionClass('Exception'))->getProperty('trace');
|
||||
$traceProperty->setAccessible(true);
|
||||
|
||||
$flatten = static function (&$value) {
|
||||
if ($value instanceof Closure) {
|
||||
$closureReflection = new ReflectionFunction($value);
|
||||
$value = sprintf(
|
||||
'(Closure at %s:%s)',
|
||||
$closureReflection->getFileName(),
|
||||
$closureReflection->getStartLine()
|
||||
);
|
||||
} elseif (is_object($value)) {
|
||||
$value = sprintf('object(%s)', get_class($value));
|
||||
} elseif (is_resource($value)) {
|
||||
$value = sprintf('resource(%s)', get_resource_type($value));
|
||||
}
|
||||
};
|
||||
$flatten =
|
||||
/** @param mixed $value */
|
||||
static function (&$value) : void {
|
||||
if ($value instanceof Closure) {
|
||||
$closureReflection = new ReflectionFunction($value);
|
||||
$value = sprintf(
|
||||
'(Closure at %s:%s)',
|
||||
$closureReflection->getFileName(),
|
||||
$closureReflection->getStartLine()
|
||||
);
|
||||
} elseif (is_object($value)) {
|
||||
$value = sprintf('object(%s)', get_class($value));
|
||||
} elseif (is_resource($value)) {
|
||||
$value = sprintf('resource(%s)', get_resource_type($value));
|
||||
}
|
||||
};
|
||||
|
||||
do {
|
||||
$trace = array_map(
|
||||
static function($call) use ($flatten) {
|
||||
static function (array $call) use ($flatten) : array {
|
||||
array_walk_recursive($call['args'], $flatten);
|
||||
|
||||
return $call;
|
||||
@@ -102,7 +111,8 @@ final class InvalidTag implements Tag
|
||||
$exception->getTrace()
|
||||
);
|
||||
$traceProperty->setValue($exception, $trace);
|
||||
} while ($exception = $exception->getPrevious());
|
||||
$exception = $exception->getPrevious();
|
||||
} while ($exception !== null);
|
||||
|
||||
$traceProperty->setAccessible(false);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,10 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Throwable;
|
||||
use function fopen;
|
||||
use function serialize;
|
||||
use function unserialize;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\InvalidTag
|
||||
@@ -38,7 +42,7 @@ final class InvalidTagTest extends TestCase
|
||||
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame('Body', (string)$tag);
|
||||
self::assertSame('Body', (string) $tag);
|
||||
self::assertSame($exception, $tag->getException());
|
||||
}
|
||||
|
||||
@@ -46,9 +50,9 @@ final class InvalidTagTest extends TestCase
|
||||
{
|
||||
try {
|
||||
$this->throwExceptionFromClosureWithClosureArgument();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
$parentException = new Exception('test', 0, $e);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame($parentException, $tag->getException());
|
||||
@@ -58,36 +62,36 @@ final class InvalidTagTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
private function throwExceptionFromClosureWithClosureArgument()
|
||||
private function throwExceptionFromClosureWithClosureArgument() : void
|
||||
{
|
||||
$function = function() {
|
||||
$function = static function () : void {
|
||||
throw new InvalidArgumentException();
|
||||
};
|
||||
|
||||
$function($function);
|
||||
}
|
||||
|
||||
public function testCreationWithErrorContainingResource()
|
||||
public function testCreationWithErrorContainingResource() : void
|
||||
{
|
||||
try {
|
||||
$this->throwExceptionWithResourceArgument();
|
||||
} catch (Exception $e) {
|
||||
} catch (Throwable $e) {
|
||||
$parentException = new Exception('test', 0, $e);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($parentException);
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame($parentException, $tag->getException());
|
||||
self::assertStringStartsWith(
|
||||
'resource(stream)',
|
||||
$tag->getException()->getPrevious()->getTrace()[0]['args'][0])
|
||||
;
|
||||
$tag->getException()->getPrevious()->getTrace()[0]['args'][0]
|
||||
);
|
||||
self::assertEquals($parentException, unserialize(serialize($parentException)));
|
||||
}
|
||||
}
|
||||
|
||||
private function throwExceptionWithResourceArgument()
|
||||
private function throwExceptionWithResourceArgument() : void
|
||||
{
|
||||
$function = function() {
|
||||
$function = static function () : void {
|
||||
throw new InvalidArgumentException();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user