diff --git a/src/Reactor/src/AbstractDeclaration.php b/src/Reactor/src/AbstractDeclaration.php index c84535548..fdde8d6eb 100644 --- a/src/Reactor/src/AbstractDeclaration.php +++ b/src/Reactor/src/AbstractDeclaration.php @@ -10,6 +10,8 @@ /** * Generic element declaration. + * + * @template T of ClassLike */ abstract class AbstractDeclaration implements DeclarationInterface, NamedInterface, \Stringable { @@ -17,6 +19,9 @@ abstract class AbstractDeclaration implements DeclarationInterface, NamedInterfa use Traits\NameAware; use Traits\AttributeAware; + /** + * @var T + */ protected ClassLike $element; public function __toString(): string diff --git a/src/Reactor/src/ClassDeclaration.php b/src/Reactor/src/ClassDeclaration.php index 7236bf1d8..18a3d7b52 100644 --- a/src/Reactor/src/ClassDeclaration.php +++ b/src/Reactor/src/ClassDeclaration.php @@ -11,6 +11,9 @@ use Spiral\Reactor\Partial\TraitUse; use Spiral\Reactor\Traits; +/** + * @extends AbstractDeclaration + */ class ClassDeclaration extends AbstractDeclaration implements AggregableInterface { use Traits\ConstantsAware; diff --git a/src/Reactor/src/EnumDeclaration.php b/src/Reactor/src/EnumDeclaration.php index f6c8ebee9..6d494f4ac 100644 --- a/src/Reactor/src/EnumDeclaration.php +++ b/src/Reactor/src/EnumDeclaration.php @@ -13,6 +13,9 @@ use Spiral\Reactor\Partial\TraitUse; use Spiral\Reactor\Traits; +/** + * @extends AbstractDeclaration + */ class EnumDeclaration extends AbstractDeclaration implements AggregableInterface { use Traits\ConstantsAware; diff --git a/src/Reactor/src/InterfaceDeclaration.php b/src/Reactor/src/InterfaceDeclaration.php index 71fcdd4ef..91833d55e 100644 --- a/src/Reactor/src/InterfaceDeclaration.php +++ b/src/Reactor/src/InterfaceDeclaration.php @@ -9,6 +9,9 @@ use Spiral\Reactor\Partial\Method; use Spiral\Reactor\Traits; +/** + * @extends AbstractDeclaration + */ class InterfaceDeclaration extends AbstractDeclaration implements AggregableInterface { use Traits\ConstantsAware; diff --git a/src/Reactor/src/Partial/Parameter.php b/src/Reactor/src/Partial/Parameter.php index 60bc99949..164890cf3 100644 --- a/src/Reactor/src/Partial/Parameter.php +++ b/src/Reactor/src/Partial/Parameter.php @@ -11,6 +11,9 @@ use Spiral\Reactor\NamedInterface; use Spiral\Reactor\Traits; +/** + * @property NetteParameter $element + */ class Parameter implements NamedInterface, AggregableInterface { use Traits\AttributeAware; diff --git a/src/Reactor/src/Partial/PromotedParameter.php b/src/Reactor/src/Partial/PromotedParameter.php index eb053cf9d..78336dcd9 100644 --- a/src/Reactor/src/Partial/PromotedParameter.php +++ b/src/Reactor/src/Partial/PromotedParameter.php @@ -8,6 +8,9 @@ use Nette\PhpGenerator\PromotedParameter as NettePromotedParameter; use Spiral\Reactor\Traits; +/** + * @property NettePromotedParameter $element + */ final class PromotedParameter extends Parameter { use Traits\CommentAware; diff --git a/src/Reactor/src/TraitDeclaration.php b/src/Reactor/src/TraitDeclaration.php index e28127ab8..4eaa5d672 100644 --- a/src/Reactor/src/TraitDeclaration.php +++ b/src/Reactor/src/TraitDeclaration.php @@ -11,6 +11,9 @@ use Spiral\Reactor\Partial\TraitUse; use Spiral\Reactor\Traits; +/** + * @extends AbstractDeclaration + */ class TraitDeclaration extends AbstractDeclaration implements AggregableInterface { use Traits\ConstantsAware; diff --git a/src/Reactor/src/Traits/TraitsAware.php b/src/Reactor/src/Traits/TraitsAware.php index c6154e370..be97f7062 100644 --- a/src/Reactor/src/Traits/TraitsAware.php +++ b/src/Reactor/src/Traits/TraitsAware.php @@ -36,9 +36,9 @@ public function getTrait(string $name): TraitUse return $this->getTraits()->get($name); } - public function addTrait(string $name, array|bool|null $deprecatedParam = null): TraitUse + public function addTrait(string $name): TraitUse { - return TraitUse::fromElement($this->element->addTrait($name, $deprecatedParam)); + return TraitUse::fromElement($this->element->addTrait($name)); } public function removeTrait(string $name): static diff --git a/src/Reactor/tests/FileDeclarationTest.php b/src/Reactor/tests/FileDeclarationTest.php index 644b3f868..f1086d2bd 100644 --- a/src/Reactor/tests/FileDeclarationTest.php +++ b/src/Reactor/tests/FileDeclarationTest.php @@ -130,6 +130,7 @@ public function testAddUse(): void { $file = new FileDeclaration(); $file->addUse('Foo\\Bar'); + $file->addClass('Test')->addImplement('Foo\\Bar'); $this->assertStringContainsString('use Foo\\Bar;', (string) $file); } diff --git a/src/Reactor/tests/Partial/PhpNamespaceTest.php b/src/Reactor/tests/Partial/PhpNamespaceTest.php index 77193191a..c7e20df8f 100644 --- a/src/Reactor/tests/Partial/PhpNamespaceTest.php +++ b/src/Reactor/tests/Partial/PhpNamespaceTest.php @@ -44,14 +44,17 @@ public function testAddUse(): void $this->assertEmpty($namespace->getUses()); - $namespace->addUse('foo'); - $namespace->addUse('bar', 'baz'); - $this->assertSame(['baz' => 'bar', 'foo' => 'foo'], $namespace->getUses()); - $this->assertStringContainsString('use bar as baz;', $namespace->__toString()); - $this->assertStringContainsString('use foo;', $namespace->__toString()); + $namespace->addUse('Some\\Other'); + $namespace->addUse('Other\\Some', 'Baz'); + $namespace->addClass('Test')->setExtends('Some\\Other')->addImplement('Baz'); - $namespace->removeUse('bar'); - $this->assertSame(['foo' => 'foo'], $namespace->getUses()); + $this->assertSame(['Baz' => 'Other\\Some', 'Other' => 'Some\\Other'], $namespace->getUses()); + + $this->assertStringContainsString('use Other\\Some as Baz;', $namespace->__toString()); + $this->assertStringContainsString('use Some\\Other;', $namespace->__toString()); + + $namespace->removeUse('Other\\Some'); + $this->assertSame(['Other' => 'Some\\Other'], $namespace->getUses()); } public function testUseFunction(): void @@ -62,6 +65,8 @@ public function testUseFunction(): void $namespace->addUseFunction('foo'); $namespace->addUseFunction('bar', 'baz'); + $namespace->addClass('Test')->addMethod('test')->addBody('foo();baz();'); + $this->assertSame(['baz' => 'bar', 'foo' => 'foo'], $namespace->getUses(NettePhpNamespace::NameFunction)); $this->assertStringContainsString('use function bar as baz;', $namespace->__toString()); $this->assertStringContainsString('use function foo;', $namespace->__toString()); @@ -78,6 +83,8 @@ public function testUseConstant(): void $namespace->addUseConstant('foo'); $namespace->addUseConstant('bar', 'baz'); + $namespace->addClass('Test')->addMethod('test')->addBody('foo::some;baz::some;'); + $this->assertSame(['baz' => 'bar', 'foo' => 'foo'], $namespace->getUses(NettePhpNamespace::NameConstant)); $this->assertStringContainsString('use const bar as baz;', $namespace->__toString()); $this->assertStringContainsString('use const foo;', $namespace->__toString()); @@ -175,6 +182,7 @@ public function testAddEnum(): void public function testRender(): void { $namespace = new PhpNamespace('Foo\\Bar'); + $namespace->addClass('Test'); $this->assertStringContainsString('namespace Foo\\Bar;', $namespace->__toString()); }