This repository was archived by the owner on Jan 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,11 @@ public static function fromReflection(PropertyReflection $reflectionProperty)
46
46
47
47
$ allDefaultProperties = $ reflectionProperty ->getDeclaringClass ()->getDefaultProperties ();
48
48
49
- $ property ->setDefaultValue ($ allDefaultProperties [$ reflectionProperty ->getName ()]);
49
+ $ defaultValue = $ allDefaultProperties [$ reflectionProperty ->getName ()];
50
+ $ property ->setDefaultValue ($ defaultValue );
51
+ if ($ defaultValue === null ) {
52
+ $ property ->omitDefaultValue = true ;
53
+ }
50
54
51
55
if ($ reflectionProperty ->getDocComment () != '' ) {
52
56
$ property ->setDocBlock (DocBlockGenerator::fromReflection ($ reflectionProperty ->getDocBlock ()));
Original file line number Diff line number Diff line change @@ -291,4 +291,15 @@ public function testOmitType()
291
291
292
292
self ::assertEquals (' public $foo; ' , $ property ->generate ());
293
293
}
294
+
295
+ public function testFromReflectionOmitsDefaultValueIfItIsNull () : void
296
+ {
297
+ $ reflectionClass = new ClassReflection (TestAsset \TestClassWithManyProperties::class);
298
+ $ propertyReflection = $ reflectionClass ->getProperty ('fooStaticProperty ' );
299
+
300
+ $ generator = PropertyGenerator::fromReflection ($ propertyReflection );
301
+ $ code = $ generator ->generate ();
302
+
303
+ $ this ->assertEquals (' public static $fooStaticProperty; ' , $ code );
304
+ }
294
305
}
You can’t perform that action at this time.
0 commit comments