diff --git a/src/Property.php b/src/Property.php index 035bc98..2fca957 100644 --- a/src/Property.php +++ b/src/Property.php @@ -56,7 +56,7 @@ public static function new( public function generate(): string { $docBlock = $this->docBlock ? "$this->docBlock\n" : ''; - $value = $this->value ? " = $this->value" : ''; + $value = $this->value !== '' ? " = $this->value" : ''; $isStatic = $this->isStatic ? 'static ' : ''; $typeHint = ''; diff --git a/tests/PropertyTest.php b/tests/PropertyTest.php index 9884d26..07aef51 100644 --- a/tests/PropertyTest.php +++ b/tests/PropertyTest.php @@ -22,6 +22,23 @@ public function createProperty(): void $this->assertEquals($anotherName, $property->getName()); $this->assertEquals(Modifier::PUBLIC, $property->getModifier()); + $property->setTypeHint('int'); + $this->assertEquals("public int $$anotherName", $property->generate()); + + $property->setDefaultValue(0); + $this->assertEquals("public int $$anotherName = 0", $property->generate()); + + $property->setDefaultValue(Property::NO_PARAM); + $this->assertEquals("public int $$anotherName", $property->generate()); + + $property->setTypeHint(''); + $property->setDefaultValue(''); + $this->assertEquals("public $$anotherName = ''", $property->generate()); + + $property->setDefaultValue(null); + $this->assertEquals("public $$anotherName = null", $property->generate()); + + $property->setDefaultValue(Property::NO_PARAM); $property->setStatic(); $this->assertTrue($property->isStatic); $this->assertEquals("public static $$anotherName", $property->generate());