Skip to content

Commit e45595f

Browse files
committed
Constant: type can be nullable
1 parent 5ae2c83 commit e45595f

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/PhpGenerator/Constant.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function isFinal(): bool
5353

5454
public function setType(?string $type): static
5555
{
56-
$this->type = Helpers::validateType($type);
56+
Helpers::validateType($type);
57+
$this->type = $type;
5758
return $this;
5859
}
5960

tests/PhpGenerator/ClassType.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ $trait2 = $class->addTrait('AnotherTrait')
3939
$class->addConstant('ROLE', 'admin');
4040
$class->addConstant('ACTIVE', false)
4141
->setFinal()
42-
->setType('bool');
42+
->setType('?bool');
4343
Assert::true($class->hasConstant('ROLE'));
4444
Assert::false($class->hasConstant('xxx'));
4545

tests/PhpGenerator/expected/ClassType.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract class Example extends ParentClass implements IExample, IOne
1717
}
1818

1919
public const ROLE = 'admin';
20-
final public const bool ACTIVE = false;
20+
final public const ?bool ACTIVE = false;
2121

2222
/** Commented */
2323
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;

0 commit comments

Comments
 (0)