From 03acaa6bb5016e4ea9ed205b1bec96a432458f14 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Fri, 1 Nov 2024 12:57:50 +0100 Subject: [PATCH] Constant: type can be nullable --- src/PhpGenerator/Constant.php | 3 ++- tests/PhpGenerator/ClassType.phpt | 2 +- tests/PhpGenerator/expected/ClassType.expect | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) 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;