From 3e116ab99ff1ba7d986dc1c467efdb7763eafd61 Mon Sep 17 00:00:00 2001 From: Jaapio <jaap@ijaap.nl> Date: Tue, 28 Dec 2021 21:35:05 +0100 Subject: [PATCH] WIP attributes --- .../Reflection/Php/Attribute_.php | 10 +++++ .../Php/Factory/AbstractFactory.php | 2 + .../Reflection/Php/Factory/Attribute_.php | 21 ++++++++++ .../Reflection/Php/Factory/Class_.php | 1 - tests/integration/AttributesTest.php | 40 +++++++++++++++++++ .../data/Attributes/AttributeConsumer.php | 21 ++++++++++ 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/phpDocumentor/Reflection/Php/Attribute_.php create mode 100644 src/phpDocumentor/Reflection/Php/Factory/Attribute_.php create mode 100644 tests/integration/AttributesTest.php create mode 100644 tests/integration/data/Attributes/AttributeConsumer.php diff --git a/src/phpDocumentor/Reflection/Php/Attribute_.php b/src/phpDocumentor/Reflection/Php/Attribute_.php new file mode 100644 index 00000000..3011a11a --- /dev/null +++ b/src/phpDocumentor/Reflection/Php/Attribute_.php @@ -0,0 +1,10 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Php; + +final class Attribute_ +{ + +} diff --git a/src/phpDocumentor/Reflection/Php/Factory/AbstractFactory.php b/src/phpDocumentor/Reflection/Php/Factory/AbstractFactory.php index 9a0d9dc1..1c9d77be 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/AbstractFactory.php +++ b/src/phpDocumentor/Reflection/Php/Factory/AbstractFactory.php @@ -77,4 +77,6 @@ protected function createDocBlock(?Doc $docBlock = null, ?Context $context = nul return $this->docBlockFactory->create($docBlock->getText(), $context); } + + protected function processAttributes() } diff --git a/src/phpDocumentor/Reflection/Php/Factory/Attribute_.php b/src/phpDocumentor/Reflection/Php/Factory/Attribute_.php new file mode 100644 index 00000000..14fc83b0 --- /dev/null +++ b/src/phpDocumentor/Reflection/Php/Factory/Attribute_.php @@ -0,0 +1,21 @@ +<?php + +declare(strict_types=1); + +namespace phpDocumentor\Reflection\Php\Factory; + +use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; +use phpDocumentor\Reflection\Php\StrategyContainer; + +final class Attribute_ implements ProjectFactoryStrategy +{ + public function matches(ContextStack $context, object $object): bool + { + + } + + public function create(ContextStack $context, object $object, StrategyContainer $strategies): void + { + // TODO: Implement create() method. + } +} diff --git a/src/phpDocumentor/Reflection/Php/Factory/Class_.php b/src/phpDocumentor/Reflection/Php/Factory/Class_.php index 98403b80..26d9ab4f 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Class_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Class_.php @@ -45,7 +45,6 @@ public function matches(ContextStack $context, object $object): bool protected function doCreate(ContextStack $context, object $object, StrategyContainer $strategies): void { $docBlock = $this->createDocBlock($object->getDocComment(), $context->getTypeContext()); - $classElement = new ClassElement( $object->fqsen, $docBlock, diff --git a/tests/integration/AttributesTest.php b/tests/integration/AttributesTest.php new file mode 100644 index 00000000..823b85fb --- /dev/null +++ b/tests/integration/AttributesTest.php @@ -0,0 +1,40 @@ +<?php + +declare(strict_types=1); + +namespace integration; + +use phpDocumentor\Reflection\File\LocalFile; +use phpDocumentor\Reflection\Php\Class_; +use phpDocumentor\Reflection\Php\ProjectFactory; +use phpDocumentor\Reflection\Php\Project; +use PHPUnit\Framework\TestCase; + +final class AttributesTest extends TestCase +{ + const FILE = __DIR__ . '/data/Attributes/AttributeConsumer.php'; + + /** @var Project */ + private $project; + + protected function setUp() : void + { + $fixture = ProjectFactory::createInstance(); + $this->project = $fixture->create( + 'MyProject', + [ + new LocalFile(self::FILE), + ] + ); + } + + public function testClassHasDocblock(): void + { + $file = $this->project->getFiles()[self::FILE]; + /** @var Class_ $class */ + $class = $file->getClasses()['\AttributeConsumer']; + + self::assertNotNull($class->getDocBlock()); + self::assertSame('Class docblock', $class->getDocBlock()->getSummary()); + } +} diff --git a/tests/integration/data/Attributes/AttributeConsumer.php b/tests/integration/data/Attributes/AttributeConsumer.php new file mode 100644 index 00000000..9d73252c --- /dev/null +++ b/tests/integration/data/Attributes/AttributeConsumer.php @@ -0,0 +1,21 @@ +<?php + +declare(strict_types=1); + +/** Class docblock */ +#[MyClassAttribute(4)] +#[MyClassAttribute2("FirstValue", 2)] +class AttributeConsumer +{ + /** @return void */ + #[MethodAttribute] + public function docblockBefore(): void + { + } + + /** @return void */ + #[MethodAttribute] + public function docblockAfter(): void + { + } +}