From b66b6dc6447c9a30073d83e377cb099d899a6839 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Fri, 28 Oct 2022 14:54:08 +0200 Subject: [PATCH] Fix some php8+ issues --- phpcs.xml.dist | 5 +---- src/DocBlock/StandardTagFactory.php | 8 +++++++- src/DocBlock/TagFactory.php | 5 ++--- src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php | 3 +-- src/DocBlock/Tags/Factory/Factory.php | 1 - src/DocBlockFactory.php | 4 ++-- tests/unit/DocBlock/StandardTagFactoryTest.php | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 27aa317..03c8954 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,13 +10,10 @@ - + - - - diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index b728d58..eb0c75b 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -41,6 +41,7 @@ use ReflectionNamedType; use ReflectionParameter; use Webmozart\Assert\Assert; +use function array_key_exists; use function array_merge; use function array_slice; use function call_user_func_array; @@ -48,6 +49,7 @@ use function count; use function get_class; use function is_object; use function preg_match; +use function sprintf; use function strpos; use function trim; @@ -164,6 +166,7 @@ final class StandardTagFactory implements TagFactory $this->serviceLocator[$alias ?: get_class($service)] = $service; } + /** {@inheritDoc} */ public function registerTagHandler(string $tagName, $handler): void { Assert::stringNotEmpty($tagName); @@ -176,6 +179,7 @@ final class StandardTagFactory implements TagFactory if (is_object($handler)) { Assert::implementsInterface($handler, TagFactory::class); $this->tagHandlerMappings[$tagName] = $handler; + return; } @@ -217,7 +221,9 @@ final class StandardTagFactory implements TagFactory $this->getServiceLocatorWithDynamicParameters($context, $name, $body) ); - $arguments['tagLine'] = sprintf('@%s %s', $name, $body); + if (array_key_exists('tagLine', $arguments)) { + $arguments['tagLine'] = sprintf('@%s %s', $name, $body); + } try { $callable = [$handlerClassName, 'create']; diff --git a/src/DocBlock/TagFactory.php b/src/DocBlock/TagFactory.php index 9dec799..a6f1ae8 100644 --- a/src/DocBlock/TagFactory.php +++ b/src/DocBlock/TagFactory.php @@ -15,7 +15,6 @@ namespace phpDocumentor\Reflection\DocBlock; use InvalidArgumentException; use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; -use phpDocumentor\Reflection\Types\Context as TypeContext; interface TagFactory extends Factory { @@ -61,7 +60,7 @@ interface TagFactory extends Factory * * @param string $tagName Name of tag to register a handler for. When registering a namespaced * tag, the full name, along with a prefixing slash MUST be provided. - * @param class-string $handler FQCN of handler. + * @param class-string|Factory $handler FQCN of handler. * * @throws InvalidArgumentException If the tag name is not a string. * @throws InvalidArgumentException If the tag name is namespaced (contains backslashes) but @@ -70,5 +69,5 @@ interface TagFactory extends Factory * @throws InvalidArgumentException If the handler is not an existing class. * @throws InvalidArgumentException If the handler does not implement the {@see Tag} interface. */ - public function registerTagHandler(string $tagName, string $handler): void; + public function registerTagHandler(string $tagName, $handler): void; } diff --git a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php index 281cbbc..62d32f2 100644 --- a/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php +++ b/src/DocBlock/Tags/Factory/AbstractPHPStanFactory.php @@ -13,9 +13,7 @@ declare(strict_types=1); namespace phpDocumentor\Reflection\DocBlock\Tags\Factory; -use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; use phpDocumentor\Reflection\DocBlock\Tag; -use phpDocumentor\Reflection\DocBlock\TagFactory; use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; use phpDocumentor\Reflection\Types\Context as TypeContext; use PHPStan\PhpDocParser\Lexer\Lexer; @@ -36,6 +34,7 @@ class AbstractPHPStanFactory implements Factory { private PhpDocParser $parser; private Lexer $lexer; + /** @var PHPStanFactory[] */ private array $factories; public function __construct(PHPStanFactory ...$factories) diff --git a/src/DocBlock/Tags/Factory/Factory.php b/src/DocBlock/Tags/Factory/Factory.php index a8c94b6..190d3ff 100644 --- a/src/DocBlock/Tags/Factory/Factory.php +++ b/src/DocBlock/Tags/Factory/Factory.php @@ -28,7 +28,6 @@ use phpDocumentor\Reflection\Types\Context as TypeContext; interface Factory { - /** * Factory method responsible for instantiating the correct sub type. * diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index f75a02c..2599e54 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -16,11 +16,11 @@ namespace phpDocumentor\Reflection; use InvalidArgumentException; use LogicException; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; -use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; use phpDocumentor\Reflection\DocBlock\StandardTagFactory; use phpDocumentor\Reflection\DocBlock\Tag; use phpDocumentor\Reflection\DocBlock\TagFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\TypeFactory; use Webmozart\Assert\Assert; @@ -42,7 +42,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface /** @var DocBlock\DescriptionFactory */ private $descriptionFactory; - /** @var \phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory */ + /** @var Factory */ private $tagFactory; /** diff --git a/tests/unit/DocBlock/StandardTagFactoryTest.php b/tests/unit/DocBlock/StandardTagFactoryTest.php index 893c3b6..5a954d5 100644 --- a/tests/unit/DocBlock/StandardTagFactoryTest.php +++ b/tests/unit/DocBlock/StandardTagFactoryTest.php @@ -228,7 +228,7 @@ class StandardTagFactoryTest extends TestCase public function testTagWithHandlerObject(): void { - $fqsenResolver = new FqsenResolver(); + $fqsenResolver = new FqsenResolver(); $customFactory = new CustomTagFactory(); $injectedClass = new CustomServiceClass();