Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spiral/reactor] Fix Psalm issues and tests in Reactor #1002

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Reactor/src/AbstractDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@

/**
* Generic element declaration.
*
* @template T of ClassLike
*/
abstract class AbstractDeclaration implements DeclarationInterface, NamedInterface, \Stringable
{
use Traits\CommentAware;
use Traits\NameAware;
use Traits\AttributeAware;

/**
* @var T
*/
protected ClassLike $element;

public function __toString(): string
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/ClassDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Spiral\Reactor\Partial\TraitUse;
use Spiral\Reactor\Traits;

/**
* @extends AbstractDeclaration<ClassType>
*/
class ClassDeclaration extends AbstractDeclaration implements AggregableInterface
{
use Traits\ConstantsAware;
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/EnumDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use Spiral\Reactor\Partial\TraitUse;
use Spiral\Reactor\Traits;

/**
* @extends AbstractDeclaration<EnumType>
*/
class EnumDeclaration extends AbstractDeclaration implements AggregableInterface
{
use Traits\ConstantsAware;
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/InterfaceDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Spiral\Reactor\Partial\Method;
use Spiral\Reactor\Traits;

/**
* @extends AbstractDeclaration<InterfaceType>
*/
class InterfaceDeclaration extends AbstractDeclaration implements AggregableInterface
{
use Traits\ConstantsAware;
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/Partial/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Spiral\Reactor\NamedInterface;
use Spiral\Reactor\Traits;

/**
* @property NetteParameter $element
*/
class Parameter implements NamedInterface, AggregableInterface
{
use Traits\AttributeAware;
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/Partial/PromotedParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Reactor/src/TraitDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Spiral\Reactor\Partial\TraitUse;
use Spiral\Reactor\Traits;

/**
* @extends AbstractDeclaration<TraitType>
*/
class TraitDeclaration extends AbstractDeclaration implements AggregableInterface
{
use Traits\ConstantsAware;
Expand Down
4 changes: 2 additions & 2 deletions src/Reactor/src/Traits/TraitsAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Reactor/tests/FileDeclarationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 15 additions & 7 deletions src/Reactor/tests/Partial/PhpNamespaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
}
Expand Down
Loading