Skip to content

Commit

Permalink
Fixied PromotedParameter in the Reactor (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Apr 20, 2023
1 parent 566d6a2 commit 2a98a77
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -28,7 +28,7 @@
],
"require": {
"php": ">=8.1",
"spiral/files": "^3.7",
"spiral/files": "^3.8",
"doctrine/inflector": "^1.4|^2.0",
"nette/php-generator": "^4.0.1"
},
Expand All @@ -50,7 +50,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.7.x-dev"
"dev-master": "3.8.x-dev"
}
},
"config": {
Expand Down
10 changes: 5 additions & 5 deletions src/Partial/Parameter.php
Expand Up @@ -16,14 +16,14 @@ class Parameter implements NamedInterface, AggregableInterface
use Traits\AttributeAware;
use Traits\NameAware;

private NetteParameter $element;
protected NettePromotedParameter|NetteParameter $element;

public function __construct(string $name)
{
$this->element = new NetteParameter((new InflectorFactory())->build()->camelize($name));
}

public function setReference(bool $state = true): self
public function setReference(bool $state = true): static
{
$this->element->setReference($state);

Expand All @@ -35,7 +35,7 @@ public function isReference(): bool
return $this->element->isReference();
}

public function setType(?string $type): self
public function setType(?string $type): static
{
$this->element->setType($type);

Expand All @@ -49,7 +49,7 @@ public function getType(): ?string
return $type === null ? null : (string) $type;
}

public function setNullable(bool $state = true): self
public function setNullable(bool $state = true): static
{
$this->element->setNullable($state);

Expand All @@ -61,7 +61,7 @@ public function isNullable(): bool
return $this->element->isNullable();
}

public function setDefaultValue(mixed $value): self
public function setDefaultValue(mixed $value): static
{
$this->element->setDefaultValue($value);

Expand Down
2 changes: 0 additions & 2 deletions src/Partial/PromotedParameter.php
Expand Up @@ -13,8 +13,6 @@ final class PromotedParameter extends Parameter
use Traits\CommentAware;
use Traits\VisibilityAware;

private NettePromotedParameter $element;

public function __construct(string $name)
{
$this->element = new NettePromotedParameter((new InflectorFactory())->build()->camelize($name));
Expand Down
17 changes: 15 additions & 2 deletions tests/ClassDeclarationTest.php
Expand Up @@ -97,8 +97,8 @@ public function testClassDeclarationWithMethods(): void
->setBody('return count($items ?: $this->items);');

$method->addParameter('items', [])
->setReference()
->setType('array');
->setReference()
->setType('array');

$this->assertSame(preg_replace('/\s+/', '', '
class MyClass extends Spiral\Tests\Reactor\ClassDeclarationTest implements Countable
Expand Down Expand Up @@ -251,6 +251,19 @@ final class MyClass extends Spiral\Tests\Reactor\ClassDeclarationTest implements
$this->assertSame($expect, preg_replace('/\s+/', '', $class->__toString()));
}

public function testRenderPromotedParameter(): void
{
$class = new ClassDeclaration('MyClass');

$class->addMethod('__construct')
->addPromotedParameter('foo')
->setType('string')
->setPrivate()
->setReadOnly();

$this->assertStringContainsString('private readonly string $foo', $class->render());
}

public function testFromElement(): void
{
$class = ClassDeclaration::fromElement(new ClassType('Test'));
Expand Down

0 comments on commit 2a98a77

Please sign in to comment.