diff --git a/src/phpDocumentor/Reflection/Php/Factory/Property.php b/src/phpDocumentor/Reflection/Php/Factory/Property.php index 5b32c179..8232dcf5 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Property.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Property.php @@ -18,6 +18,7 @@ use phpDocumentor\Reflection\Location; use phpDocumentor\Reflection\Php\Class_; use phpDocumentor\Reflection\Php\Factory\Reducer\Reducer; +use phpDocumentor\Reflection\Php\Interface_; use phpDocumentor\Reflection\Php\Property as PropertyDescriptor; use phpDocumentor\Reflection\Php\StrategyContainer; use phpDocumentor\Reflection\Php\Trait_; @@ -69,6 +70,7 @@ protected function doCreate( [ Class_::class, Trait_::class, + Interface_::class, ], ); diff --git a/src/phpDocumentor/Reflection/Php/Interface_.php b/src/phpDocumentor/Reflection/Php/Interface_.php index a38ca067..64ce1ac6 100644 --- a/src/phpDocumentor/Reflection/Php/Interface_.php +++ b/src/phpDocumentor/Reflection/Php/Interface_.php @@ -37,6 +37,9 @@ final class Interface_ implements Element, MetaDataContainerInterface, Attribute /** @var Method[] */ private array $methods = []; + /** @var Property[] */ + private array $properties = []; + private readonly Location $location; private readonly Location $endLocation; @@ -95,6 +98,24 @@ public function addMethod(Method $method): void $this->methods[(string) $method->getFqsen()] = $method; } + /** + * Returns the properties of this interface. + * + * @return Property[] + */ + public function getProperties(): array + { + return $this->properties; + } + + /** + * Add a property to this interface. + */ + public function addProperty(Property $property): void + { + $this->properties[(string) $property->getFqsen()] = $property; + } + /** * Returns the Fqsen of the element. */ diff --git a/tests/integration/InterfacePropertyTest.php b/tests/integration/InterfacePropertyTest.php new file mode 100644 index 00000000..f7760f69 --- /dev/null +++ b/tests/integration/InterfacePropertyTest.php @@ -0,0 +1,44 @@ += 5.2')] +#[CoversNothing] +final class InterfacePropertyTest extends TestCase +{ + public function testInterfacePropertiesAreParsed(): void + { + $file = __DIR__ . '/data/PHP84/InterfaceProperties.php'; + $projectFactory = ProjectFactory::createInstance(); + $project = $projectFactory->create('My project', [new LocalFile($file)]); + + $interfaces = $project->getFiles()[$file]->getInterfaces(); + + $hasId = $interfaces['\PHP84\HasId']; + $properties = $hasId->getProperties(); + $this->assertCount(1, $properties); + $idProperty = $properties['\PHP84\HasId::$id']; + $this->assertEquals(new Integer(), $idProperty->getType()); + $this->assertEquals(new Visibility(Visibility::PUBLIC_), $idProperty->getVisibility()); + $this->assertCount(1, $idProperty->getHooks()); + $this->assertEquals('get', $idProperty->getHooks()[0]->getName()); + + $hasName = $interfaces['\PHP84\HasName']; + $properties = $hasName->getProperties(); + $this->assertCount(1, $properties); + $nameProperty = $properties['\PHP84\HasName::$name']; + $this->assertEquals(new String_(), $nameProperty->getType()); + $this->assertCount(2, $nameProperty->getHooks()); + } +} diff --git a/tests/integration/data/PHP84/InterfaceProperties.php b/tests/integration/data/PHP84/InterfaceProperties.php new file mode 100644 index 00000000..4ba761dd --- /dev/null +++ b/tests/integration/data/PHP84/InterfaceProperties.php @@ -0,0 +1,15 @@ +assertEquals(['\MySpace\MyInterface::myMethod()' => $method], $this->fixture->getMethods()); } + public function testSettingAndGettingProperties(): void + { + $this->assertEquals([], $this->fixture->getProperties()); + + $property = new Property(new Fqsen('\MySpace\MyInterface::$myProperty')); + + $this->fixture->addProperty($property); + + $this->assertEquals(['\MySpace\MyInterface::$myProperty' => $property], $this->fixture->getProperties()); + } + public function testReturningTheParentsOfThisInterface(): void { $this->assertSame($this->exampleParents, $this->fixture->getParents());