diff --git a/src/DocBlock/Tags/Factory/ParamFactory.php b/src/DocBlock/Tags/Factory/ParamFactory.php index fd0c0061..6e18df0e 100644 --- a/src/DocBlock/Tags/Factory/ParamFactory.php +++ b/src/DocBlock/Tags/Factory/ParamFactory.php @@ -9,8 +9,10 @@ use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use PHPStan\PhpDocParser\Ast\PhpDoc\InvalidTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\TypelessParamTagValueNode; use Webmozart\Assert\Assert; use function trim; @@ -32,7 +34,13 @@ public function __construct(TypeResolver $typeResolver, DescriptionFactory $desc public function create(PhpDocTagNode $node, Context $context): Tag { $tagValue = $node->value; - Assert::isInstanceOf($tagValue, ParamTagValueNode::class); + Assert::isInstanceOfAny( + $tagValue, + [ + ParamTagValueNode::class, + TypelessParamTagValueNode::class + ] + ); return new Param( trim($tagValue->parameterName, '$'), @@ -45,6 +53,7 @@ public function create(PhpDocTagNode $node, Context $context): Tag public function supports(PhpDocTagNode $node, Context $context): bool { - return $node->value instanceof ParamTagValueNode; + return $node->value instanceof ParamTagValueNode + || $node->value instanceof TypelessParamTagValueNode; } } diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index 05045c78..586c64b6 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -217,6 +217,5 @@ public function testMethodRegression(): void ], $docblock->getTags() ); - } } diff --git a/tests/unit/DocBlock/Tags/Factory/ParamFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/ParamFactoryTest.php index df2c23cd..b9f16028 100644 --- a/tests/unit/DocBlock/Tags/Factory/ParamFactoryTest.php +++ b/tests/unit/DocBlock/Tags/Factory/ParamFactoryTest.php @@ -16,6 +16,8 @@ use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; +use phpDocumentor\Reflection\Types\Mixed_; use phpDocumentor\Reflection\Types\String_; final class ParamFactoryTest extends TagFactoryTestCase @@ -24,23 +26,77 @@ final class ParamFactoryTest extends TagFactoryTestCase * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::__construct * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::create * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory::supports + * @dataProvider paramInputProvider */ - public function testParamIsCreated(): void + public function testParamIsCreated(string $input, Param $expected): void { - $ast = $this->parseTag('@param string $var'); + $ast = $this->parseTag($input); $factory = new ParamFactory($this->giveTypeResolver(), $this->givenDescriptionFactory()); $context = new Context('global'); self::assertTrue($factory->supports($ast, $context)); self::assertEquals( - new Param( - 'var', - new String_(), - false, - new Description(''), - false - ), + $expected, $factory->create($ast, $context) ); } + + /** + * @return array + */ + public function paramInputProvider(): array + { + return [ + [ + '@param string $var', + new Param( + 'var', + new String_(), + false, + new Description(''), + false + ), + ], + [ + '@param $param8 Description 4', + new Param( + 'param8', + new Mixed_(), + false, + new Description('Description 4'), + false + ), + ], + [ + '@param $param9', + new Param( + 'param9', + new Mixed_(), + false, + new Description(''), + false + ), + ], + [ + '@param int My Description', + new Param( + null, + new Integer(), + false, + new Description('My Description'), + false + ), + ], + [ + '@param foo', + new Param( + null, + new Mixed_(), + false, + new Description(''), + false + ), + ], + ]; + } } diff --git a/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php b/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php index 8684ba51..ec905654 100644 --- a/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php +++ b/tests/unit/DocBlock/Tags/Factory/TagFactoryTestCase.php @@ -45,7 +45,7 @@ public function giveTypeResolver(): TypeResolver public function givenDescriptionFactory(): DescriptionFactory { $factory = m::mock(DescriptionFactory::class); - $factory->shouldReceive('create')->andReturn(new Description('')); + $factory->shouldReceive('create')->andReturnUsing(static fn ($args) => new Description($args)); return $factory; } diff --git a/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php index 06befbb9..61f22dfd 100644 --- a/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php +++ b/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php @@ -25,7 +25,7 @@ final class VarFactoryTest extends TagFactoryTestCase * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::create * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::supports */ - public function testParamIsCreated(): void + public function testVarIsCreated(): void { $ast = $this->parseTag('@var string $var'); $factory = new VarFactory($this->giveTypeResolver(), $this->givenDescriptionFactory());