Skip to content

Commit

Permalink
Constant: type can be nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 1, 2024
1 parent e1e5e8f commit 03acaa6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/PhpGenerator/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function isFinal(): bool

public function setType(?string $type): static
{
$this->type = Helpers::validateType($type);
Helpers::validateType($type);
$this->type = $type;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/ClassType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $trait2 = $class->addTrait('AnotherTrait')
$class->addConstant('ROLE', 'admin');
$class->addConstant('ACTIVE', false)
->setFinal()
->setType('bool');
->setType('?bool');
Assert::true($class->hasConstant('ROLE'));
Assert::false($class->hasConstant('xxx'));

Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/expected/ClassType.expect
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class Example extends ParentClass implements IExample, IOne
}

public const ROLE = 'admin';
final public const bool ACTIVE = false;
final public const ?bool ACTIVE = false;

/** Commented */
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
Expand Down

0 comments on commit 03acaa6

Please sign in to comment.