diff --git a/src/PhpGenerator/Constant.php b/src/PhpGenerator/Constant.php index 44c1938c..a959efa5 100644 --- a/src/PhpGenerator/Constant.php +++ b/src/PhpGenerator/Constant.php @@ -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; } diff --git a/tests/PhpGenerator/ClassType.phpt b/tests/PhpGenerator/ClassType.phpt index a8e81eee..e22c3720 100644 --- a/tests/PhpGenerator/ClassType.phpt +++ b/tests/PhpGenerator/ClassType.phpt @@ -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')); diff --git a/tests/PhpGenerator/expected/ClassType.expect b/tests/PhpGenerator/expected/ClassType.expect index 80cef326..642dfb17 100644 --- a/tests/PhpGenerator/expected/ClassType.expect +++ b/tests/PhpGenerator/expected/ClassType.expect @@ -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;