@@ -307,10 +307,7 @@ public function generateClasses(
307307 );
308308 $ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
309309 $ classBuilder ->addProperty (
310- ClassPropertyBuilder::fromScratch (
311- $ propertyPropertyName ,
312- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
313- )
310+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
314311 );
315312 break ;
316313 case $ propertyType instanceof ReferenceType:
@@ -333,10 +330,7 @@ public function generateClasses(
333330 $ propertyType = $ propertyRefType ;
334331 }
335332 $ classBuilder ->addProperty (
336- ClassPropertyBuilder::fromScratch (
337- $ propertyPropertyName ,
338- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
339- )
333+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
340334 );
341335 $ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
342336 break ;
@@ -346,10 +340,7 @@ public function generateClasses(
346340 );
347341 $ this ->addNamespaceImport ($ classBuilder , $ propertyClassNamespace . '\\' . $ propertyClassName );
348342 $ classBuilder ->addProperty (
349- ClassPropertyBuilder::fromScratch (
350- $ propertyPropertyName ,
351- $ this ->determinePropertyType ($ propertyType , $ propertyClassName )
352- )
343+ $ this ->determineProperty ($ propertyPropertyName , $ propertyClassName , $ propertyType )
353344 );
354345 break ;
355346 default :
@@ -513,4 +504,20 @@ private function determinePropertyType(TypeDefinition $typeDefinition, string $c
513504 ? ('? ' . $ className )
514505 : $ className ;
515506 }
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+ }
516523}
0 commit comments