diff --git a/src/Generator/PropertyGenerator.php b/src/Generator/PropertyGenerator.php index 6259efc0..b5838e60 100644 --- a/src/Generator/PropertyGenerator.php +++ b/src/Generator/PropertyGenerator.php @@ -46,7 +46,11 @@ public static function fromReflection(PropertyReflection $reflectionProperty) $allDefaultProperties = $reflectionProperty->getDeclaringClass()->getDefaultProperties(); - $property->setDefaultValue($allDefaultProperties[$reflectionProperty->getName()]); + $defaultValue = $allDefaultProperties[$reflectionProperty->getName()]; + $property->setDefaultValue($defaultValue); + if ($defaultValue === null) { + $property->omitDefaultValue = true; + } if ($reflectionProperty->getDocComment() != '') { $property->setDocBlock(DocBlockGenerator::fromReflection($reflectionProperty->getDocBlock())); diff --git a/test/Generator/PropertyGeneratorTest.php b/test/Generator/PropertyGeneratorTest.php index 685c72e8..bf76903e 100644 --- a/test/Generator/PropertyGeneratorTest.php +++ b/test/Generator/PropertyGeneratorTest.php @@ -291,4 +291,15 @@ public function testOmitType() self::assertEquals(' public $foo;', $property->generate()); } + + public function testFromReflectionOmitsDefaultValueIfItIsNull() : void + { + $reflectionClass = new ClassReflection(TestAsset\TestClassWithManyProperties::class); + $propertyReflection = $reflectionClass->getProperty('fooStaticProperty'); + + $generator = PropertyGenerator::fromReflection($propertyReflection); + $code = $generator->generate(); + + $this->assertEquals(' public static $fooStaticProperty;', $code); + } }