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 @@ -308,4 +308,15 @@ public function testOmitType()
308
308
309
309
self ::assertEquals (' public $foo; ' , $ property ->generate ());
310
310
}
311
+
312
+ public function testFromReflectionOmitsDefaultValueIfItIsNull () : void
313
+ {
314
+ $ reflectionClass = new ClassReflection (TestAsset \TestClassWithManyProperties::class);
315
+ $ propertyReflection = $ reflectionClass ->getProperty ('fooStaticProperty ' );
316
+
317
+ $ generator = PropertyGenerator::fromReflection ($ propertyReflection );
318
+ $ code = $ generator ->generate ();
319
+
320
+ $ this ->assertEquals (' public static $fooStaticProperty; ' , $ code );
321
+ }
311
322
}
You can’t perform that action at this time.
0 commit comments