Skip to content

Commit f31b216

Browse files
committed
Fix check if a default value exist to determine property nullability (fixes #43)
1 parent 7dbf81a commit f31b216

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Utils/RenderHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function isPropertyNullable(PropertyInterface $property, bool $outputType
127127
{
128128
return !$property->isRequired()
129129
&& ($outputType || $this->generatorConfiguration->isImplicitNullAllowed())
130-
&& !($property->getDefaultValue() && !$this->generatorConfiguration->isImplicitNullAllowed());
130+
&& !($property->getDefaultValue() !== null && !$this->generatorConfiguration->isImplicitNullAllowed());
131131
}
132132

133133
public function getType(PropertyInterface $property, bool $outputType = false): string

tests/Basic/DefaultValueTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testTypedPropertyTypeHintsWithImplicitNullEnabledAcceptNull(): v
4444
{
4545
$className = $this->generateClassFromFileTemplate(
4646
'DefaultValueTypedProperty.json',
47-
['"integer"', 10],
47+
['"integer"', 0],
4848
(new GeneratorConfiguration())->setImmutable(false),
4949
false
5050
);
@@ -70,7 +70,7 @@ public function testTypedPropertyTypeHintsWithImplicitNullDisabledDeclinesNull()
7070
{
7171
$className = $this->generateClassFromFileTemplate(
7272
'DefaultValueTypedProperty.json',
73-
['"integer"', 10],
73+
['"integer"', 0],
7474
(new GeneratorConfiguration())->setImmutable(false),
7575
false,
7676
false

0 commit comments

Comments
 (0)