@@ -307,10 +307,7 @@ public function generateClasses(
307
307
);
308
308
$ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
309
309
$ classBuilder ->addProperty (
310
- ClassPropertyBuilder::fromScratch (
311
- $ propertyPropertyName ,
312
- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
313
- )
310
+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
314
311
);
315
312
break ;
316
313
case $ propertyType instanceof ReferenceType:
@@ -333,10 +330,7 @@ public function generateClasses(
333
330
$ propertyType = $ propertyRefType ;
334
331
}
335
332
$ classBuilder ->addProperty (
336
- ClassPropertyBuilder::fromScratch (
337
- $ propertyPropertyName ,
338
- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
339
- )
333
+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
340
334
);
341
335
$ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
342
336
break ;
@@ -346,10 +340,7 @@ public function generateClasses(
346
340
);
347
341
$ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
348
342
$ classBuilder ->addProperty (
349
- ClassPropertyBuilder::fromScratch (
350
- $ propertyPropertyName ,
351
- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
352
- )
343
+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
353
344
);
354
345
break ;
355
346
default :
@@ -513,4 +504,20 @@ private function determinePropertyType(TypeDefinition $typeDefinition, string $c
513
504
? ('? ' . $ className )
514
505
: $ className ;
515
506
}
507
+
508
+ private function determineProperty (
509
+ $ propertyName ,
510
+ $ propertyClassName ,
511
+ TypeDefinition $ typeDefinition
512
+ ): ClassPropertyBuilder {
513
+ $ property = ClassPropertyBuilder::fromScratch (
514
+ $ propertyName ,
515
+ $ this ->determinePropertyType ($ typeDefinition , $ propertyClassName )
516
+ );
517
+ if ($ typeDefinition ->isRequired () === false || $ typeDefinition ->isNullable () === true ) {
518
+ $ property ->setDefaultValue (null );
519
+ }
520
+
521
+ return $ property ;
522
+ }
516
523
}
0 commit comments