diff --git a/src/DocBlock/Tags/Factory/PropertyFactory.php b/src/DocBlock/Tags/Factory/PropertyFactory.php new file mode 100644 index 0000000..9e7ec66 --- /dev/null +++ b/src/DocBlock/Tags/Factory/PropertyFactory.php @@ -0,0 +1,47 @@ +typeFactory = $typeFactory; + $this->descriptionFactory = $descriptionFactory; + } + + public function create(PhpDocTagNode $node, ?Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + return new Property( + trim($tagValue->propertyName, '$'), + $this->typeFactory->createType($tagValue->type, $context), + $this->descriptionFactory->create($tagValue->description, $context) + ); + } + + public function supports(PhpDocTagNode $node, ?Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property'; + } +} diff --git a/src/DocBlock/Tags/Factory/PropertyReadFactory.php b/src/DocBlock/Tags/Factory/PropertyReadFactory.php new file mode 100644 index 0000000..3173428 --- /dev/null +++ b/src/DocBlock/Tags/Factory/PropertyReadFactory.php @@ -0,0 +1,47 @@ +typeFactory = $typeFactory; + $this->descriptionFactory = $descriptionFactory; + } + + public function create(PhpDocTagNode $node, ?Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + return new PropertyRead( + trim($tagValue->propertyName, '$'), + $this->typeFactory->createType($tagValue->type, $context), + $this->descriptionFactory->create($tagValue->description, $context) + ); + } + + public function supports(PhpDocTagNode $node, ?Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property-read'; + } +} diff --git a/src/DocBlock/Tags/Factory/PropertyWriteFactory.php b/src/DocBlock/Tags/Factory/PropertyWriteFactory.php new file mode 100644 index 0000000..0b6ba42 --- /dev/null +++ b/src/DocBlock/Tags/Factory/PropertyWriteFactory.php @@ -0,0 +1,47 @@ +typeFactory = $typeFactory; + $this->descriptionFactory = $descriptionFactory; + } + + public function create(PhpDocTagNode $node, ?Context $context): Tag + { + $tagValue = $node->value; + Assert::isInstanceOf($tagValue, PropertyTagValueNode::class); + + return new PropertyWrite( + trim($tagValue->propertyName, '$'), + $this->typeFactory->createType($tagValue->type, $context), + $this->descriptionFactory->create($tagValue->description, $context) + ); + } + + public function supports(PhpDocTagNode $node, ?Context $context): bool + { + return $node->value instanceof PropertyTagValueNode && $node->name === '@property-write'; + } +} diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 43ad3be..a08bdb1 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -22,6 +22,9 @@ 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\PropertyFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory; +use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\TypeFactory; use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory; @@ -73,6 +76,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface new ParamFactory($typeFactory, $descriptionFactory), new VarFactory($typeFactory, $descriptionFactory), new ReturnFactory($typeFactory, $descriptionFactory), + new PropertyFactory($typeFactory, $descriptionFactory), + new PropertyReadFactory($typeFactory, $descriptionFactory), + new PropertyWriteFactory($typeFactory, $descriptionFactory), ); $tagFactory->addService($descriptionFactory); @@ -80,6 +86,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface $tagFactory->registerTagHandler('param', $phpstanTagFactory); $tagFactory->registerTagHandler('var', $phpstanTagFactory); $tagFactory->registerTagHandler('return', $phpstanTagFactory); + $tagFactory->registerTagHandler('property', $phpstanTagFactory); + $tagFactory->registerTagHandler('property-read', $phpstanTagFactory); + $tagFactory->registerTagHandler('property-write', $phpstanTagFactory); $docBlockFactory = new self($descriptionFactory, $tagFactory); foreach ($additionalTags as $tagName => $tagHandler) { diff --git a/tests/unit/DocBlock/Tags/Factory/PropertyFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/PropertyFactoryTest.php new file mode 100644 index 0000000..c1ae0cd --- /dev/null +++ b/tests/unit/DocBlock/Tags/Factory/PropertyFactoryTest.php @@ -0,0 +1,44 @@ +parseTag('@property string $var'); + $factory = new PropertyFactory($this->giveTypeFactory(), $this->givenDescriptionFactory()); + $context = new Context('global'); + + self::assertTrue($factory->supports($ast, $context)); + self::assertEquals( + new Property( + 'var', + new String_(), + new Description('') + ), + $factory->create($ast, $context) + ); + } +} diff --git a/tests/unit/DocBlock/Tags/Factory/PropertyReadFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/PropertyReadFactoryTest.php new file mode 100644 index 0000000..2e1f4cd --- /dev/null +++ b/tests/unit/DocBlock/Tags/Factory/PropertyReadFactoryTest.php @@ -0,0 +1,44 @@ +parseTag('@property-read string $var'); + $factory = new PropertyReadFactory($this->giveTypeFactory(), $this->givenDescriptionFactory()); + $context = new Context('global'); + + self::assertTrue($factory->supports($ast, $context)); + self::assertEquals( + new PropertyRead( + 'var', + new String_(), + new Description('') + ), + $factory->create($ast, $context) + ); + } +} diff --git a/tests/unit/DocBlock/Tags/Factory/PropertyWriteFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/PropertyWriteFactoryTest.php new file mode 100644 index 0000000..af6e903 --- /dev/null +++ b/tests/unit/DocBlock/Tags/Factory/PropertyWriteFactoryTest.php @@ -0,0 +1,44 @@ +parseTag('@property-write string $var'); + $factory = new PropertyWriteFactory($this->giveTypeFactory(), $this->givenDescriptionFactory()); + $context = new Context('global'); + + self::assertTrue($factory->supports($ast, $context)); + self::assertEquals( + new PropertyWrite( + 'var', + new String_(), + new Description('') + ), + $factory->create($ast, $context) + ); + } +} diff --git a/tests/unit/DocBlock/Tags/Factory/ReturnFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/ReturnFactoryTest.php index 3d3be54..95d1e14 100644 --- a/tests/unit/DocBlock/Tags/Factory/ReturnFactoryTest.php +++ b/tests/unit/DocBlock/Tags/Factory/ReturnFactoryTest.php @@ -21,9 +21,9 @@ use phpDocumentor\Reflection\Types\String_; final class ReturnFactoryTest 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 + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory::create + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory::supports */ public function testParamIsCreated(): void { diff --git a/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php b/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php index a25058b..a37193b 100644 --- a/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php +++ b/tests/unit/DocBlock/Tags/Factory/VarFactoryTest.php @@ -21,9 +21,9 @@ use phpDocumentor\Reflection\Types\String_; final class VarFactoryTest 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 + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::__construct + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::create + * @covers \phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory::supports */ public function testParamIsCreated(): void {