mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-17 17:47:13 +00:00
Improvements to code
This commit is contained in:
@@ -229,7 +229,7 @@ final class StandardTagFactory implements TagFactory
|
||||
$callable = [$handlerClassName, 'create'];
|
||||
return call_user_func_array($callable, $arguments);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
return InvalidTag::create($body, $name, $e);
|
||||
return InvalidTag::create($body, $name)->withError($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use Throwable;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/**
|
||||
* This class represents an exception during the tag creation
|
||||
@@ -26,17 +25,16 @@ final class InvalidTag implements Tag
|
||||
/** @var string */
|
||||
private $body;
|
||||
|
||||
/** @var Throwable */
|
||||
/** @var Throwable|null */
|
||||
private $throwable;
|
||||
|
||||
private function __construct(string $name, string $body, Throwable $throwable)
|
||||
private function __construct(string $name, string $body)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->body = $body;
|
||||
$this->throwable = $throwable;
|
||||
$this->name = $name;
|
||||
$this->body = $body;
|
||||
}
|
||||
|
||||
public function getException() : Throwable
|
||||
public function getException() : ?Throwable
|
||||
{
|
||||
return $this->throwable;
|
||||
}
|
||||
@@ -47,13 +45,21 @@ final class InvalidTag implements Tag
|
||||
}
|
||||
|
||||
/**
|
||||
* @return self
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function create(string $body, string $name = '', ?Throwable $exception = null)
|
||||
public static function create(string $body, string $name = '')
|
||||
{
|
||||
Assert::notNull($exception);
|
||||
return new self($name, $body);
|
||||
}
|
||||
|
||||
return new self($name, $body, $exception);
|
||||
public function withError(Throwable $exception) : self
|
||||
{
|
||||
$tag = new self($this->name, $this->body);
|
||||
$tag->throwable = $exception;
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
public function render(?Formatter $formatter = null) : string
|
||||
|
||||
@@ -332,7 +332,7 @@ class StandardTagFactoryTest extends TestCase
|
||||
$this->assertSame('return', $tag->getName());
|
||||
}
|
||||
|
||||
public function testInvalidTagIsReturnedOnFailure()
|
||||
public function testInvalidTagIsReturnedOnFailure() : void
|
||||
{
|
||||
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpDocumentor\Reflection\DocBlock\Tags;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\InvalidTag
|
||||
* @covers ::<private>
|
||||
* @covers ::getName
|
||||
* @covers ::render
|
||||
* @covers ::getException
|
||||
* @covers ::create
|
||||
*/
|
||||
final class InvalidTagTest extends TestCase
|
||||
{
|
||||
public function testCreationWithoutError() : void
|
||||
{
|
||||
$tag = InvalidTag::create('Body', 'name');
|
||||
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertNull($tag->getException());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::withError
|
||||
*/
|
||||
public function testCreationWithError() : void
|
||||
{
|
||||
$exception = new Exception();
|
||||
$tag = InvalidTag::create('Body', 'name')->withError($exception);
|
||||
|
||||
self::assertSame('name', $tag->getName());
|
||||
self::assertSame('@name Body', $tag->render());
|
||||
self::assertSame($exception, $tag->getException());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user