@@ -122,7 +122,7 @@ public function generateClasses(
122
122
$ classBuilder ->addProperty (
123
123
ClassPropertyBuilder::fromScratch (
124
124
$ propertyPropertyName ,
125
- $ propertyType -> isNullable () ? ( ' ? ' . $ propertyClassName ) : $ propertyClassName
125
+ $ this -> determinePropertyType ( $ propertyType , $ propertyClassName)
126
126
)
127
127
);
128
128
break ;
@@ -140,7 +140,7 @@ public function generateClasses(
140
140
$ classBuilder ->addProperty (
141
141
ClassPropertyBuilder::fromScratch (
142
142
$ propertyPropertyName ,
143
- $ propertyType -> isNullable () ? ( ' ? ' . $ propertyClassName ) : $ propertyClassName
143
+ $ this -> determinePropertyType ( $ propertyType , $ propertyClassName)
144
144
)
145
145
);
146
146
$ classBuilder ->addNamespaceImport ($ classNamespace . '\\' . $ propertyClassName );
@@ -153,7 +153,7 @@ public function generateClasses(
153
153
$ classBuilder ->addProperty (
154
154
ClassPropertyBuilder::fromScratch (
155
155
$ propertyPropertyName ,
156
- $ propertyType -> isNullable () ? ( ' ? ' . $ propertyClassName ) : $ propertyClassName
156
+ $ this -> determinePropertyType ( $ propertyType , $ propertyClassName)
157
157
)
158
158
);
159
159
break ;
@@ -329,4 +329,11 @@ private function isValueObject(ClassBuilder $classBuilder): bool
329
329
|| $ classBuilder ->hasMethod ('toFloat ' )
330
330
|| $ classBuilder ->hasMethod ('toBool ' );
331
331
}
332
+
333
+ private function determinePropertyType (TypeDefinition $ typeDefinition , string $ className ): string
334
+ {
335
+ return ($ typeDefinition ->isRequired () === false || $ typeDefinition ->isNullable () === true )
336
+ ? ('? ' . $ className )
337
+ : $ className ;
338
+ }
332
339
}
0 commit comments