1919use OpenCodeModeling \JsonSchemaToPhp \Type \ArrayType ;
2020use OpenCodeModeling \JsonSchemaToPhp \Type \ReferenceType ;
2121use OpenCodeModeling \JsonSchemaToPhp \Type \ScalarType ;
22- use OpenCodeModeling \JsonSchemaToPhp \Type \StringType ;
23- use OpenCodeModeling \JsonSchemaToPhp \Type \TypeDefinition ;
2422use OpenCodeModeling \JsonSchemaToPhp \Type \TypeSet ;
2523use OpenCodeModeling \JsonSchemaToPhpAst \Common \IteratorFactory ;
2624use PhpParser \NodeVisitor ;
@@ -201,7 +199,7 @@ public function classBuilder(ArrayType $typeDefinition): ClassBuilder
201199 return $ this ->classBuilderFromNative ($ name , ...$ typeDefinition ->items ());
202200 }
203201
204- private function determineType (string $ name , TypeSet ...$ typeSets ): ?TypeDefinition
202+ private function determineTypeName (string $ name , TypeSet ...$ typeSets ): ?string
205203 {
206204 if (\count ($ typeSets ) !== 1 ) {
207205 throw new \RuntimeException ('Can only handle one JSON type ' );
@@ -219,9 +217,7 @@ private function determineType(string $name, TypeSet ...$typeSets): ?TypeDefinit
219217 $ resolvedTypeSet = $ type ->resolvedType ();
220218
221219 if ($ resolvedTypeSet === null ) {
222- $ resolvedTypeSet = new TypeSet (
223- StringType::fromDefinition (['type ' => StringType::type (), 'name ' => $ type ->name ()])
224- );
220+ return $ type ->extractNameFromReference ();
225221 }
226222 if (\count ($ resolvedTypeSet ) !== 1 ) {
227223 throw new \RuntimeException ('Can only handle one JSON type ' );
@@ -236,7 +232,7 @@ private function determineType(string $name, TypeSet ...$typeSets): ?TypeDefinit
236232 );
237233 }
238234
239- return $ type ;
235+ return $ type-> name () ;
240236 }
241237
242238 /**
@@ -246,8 +242,7 @@ private function determineType(string $name, TypeSet ...$typeSets): ?TypeDefinit
246242 */
247243 public function nodeVisitorsFromNative (string $ name , TypeSet ...$ typeSets ): array
248244 {
249- $ type = $ this ->determineType ($ name , ...$ typeSets );
250- $ typeName = $ type ->name ();
245+ $ typeName = $ this ->determineTypeName ($ name , ...$ typeSets );
251246
252247 $ nodeVisitors = $ this ->iteratorFactory ->nodeVisitorsFromNative (
253248 ($ this ->propertyNameFilter )($ name ),
@@ -273,8 +268,7 @@ public function nodeVisitorsFromNative(string $name, TypeSet ...$typeSets): arra
273268
274269 public function classBuilderFromNative (string $ name , TypeSet ...$ typeSets ): ClassBuilder
275270 {
276- $ type = $ this ->determineType ($ name , ...$ typeSets );
277- $ typeName = $ type ->name ();
271+ $ typeName = $ this ->determineTypeName ($ name , ...$ typeSets );
278272
279273 $ classBuilder = $ this ->iteratorFactory ->classBuilderFromNative (
280274 ($ this ->propertyNameFilter )($ name ),
@@ -322,10 +316,10 @@ public function methodMagicConstruct(
322316 $ method = new MethodGenerator (
323317 '__construct ' ,
324318 [
325- (new ParameterGenerator ($ argumentName , ($ this ->classNameFilter )($ argumentType )))->setVariadic (true ),
319+ (new ParameterGenerator (( $ this -> propertyNameFilter )( $ argumentName) , ($ this ->classNameFilter )($ argumentType )))->setVariadic (true ),
326320 ],
327321 MethodGenerator::FLAG_PRIVATE ,
328- new BodyGenerator ($ this ->parser , \sprintf ('$this->%s = $%s; ' , $ propertyName, $ argumentName ))
322+ new BodyGenerator ($ this ->parser , \sprintf ('$this->%s = $%s; ' , ( $ this -> propertyNameFilter )( $ propertyName), ( $ this -> propertyNameFilter )( $ argumentName) ))
329323 );
330324 $ method ->setTyped ($ this ->typed );
331325
@@ -349,7 +343,14 @@ public function methodAdd(
349343 (new ParameterGenerator (($ this ->propertyNameFilter )($ argumentType ), ($ this ->classNameFilter )($ argumentType ))),
350344 ],
351345 MethodGenerator::FLAG_PUBLIC ,
352- new BodyGenerator ($ this ->parser , \sprintf ($ body , $ propertyName , ($ this ->propertyNameFilter )($ argumentType )))
346+ new BodyGenerator (
347+ $ this ->parser ,
348+ \sprintf (
349+ $ body ,
350+ ($ this ->propertyNameFilter )($ propertyName ),
351+ ($ this ->propertyNameFilter )($ argumentType )
352+ )
353+ )
353354 );
354355 $ method ->setTyped ($ this ->typed );
355356 $ method ->setReturnType ('self ' );
@@ -378,7 +379,16 @@ static function($v) use ($%s) { return !$v->equals($%s); }
378379 (new ParameterGenerator (($ this ->propertyNameFilter )($ argumentType ), ($ this ->classNameFilter )($ argumentType ))),
379380 ],
380381 MethodGenerator::FLAG_PUBLIC ,
381- new BodyGenerator ($ this ->parser , \sprintf ($ body , $ propertyName , $ propertyName , ($ this ->propertyNameFilter )($ argumentType ), ($ this ->propertyNameFilter )($ argumentType )))
382+ new BodyGenerator (
383+ $ this ->parser ,
384+ \sprintf (
385+ $ body ,
386+ ($ this ->propertyNameFilter )($ propertyName ),
387+ ($ this ->propertyNameFilter )($ propertyName ),
388+ ($ this ->propertyNameFilter )($ argumentType ),
389+ ($ this ->propertyNameFilter )($ argumentType )
390+ )
391+ )
382392 );
383393 $ method ->setTyped ($ this ->typed );
384394 $ method ->setReturnType ('self ' );
@@ -479,7 +489,7 @@ static function($%s) use ($filter) { return $filter($%s); }
479489 new ParameterGenerator ('filter ' , 'callable ' ),
480490 ],
481491 MethodGenerator::FLAG_PUBLIC ,
482- new BodyGenerator ($ this ->parser , \sprintf ($ body , $ propertyName , 'v ' , 'v ' ))
492+ new BodyGenerator ($ this ->parser , \sprintf ($ body , ( $ this -> propertyNameFilter )( $ propertyName) , 'v ' , 'v ' ))
483493 );
484494 $ method ->setTyped ($ this ->typed );
485495 $ method ->setReturnType ('self ' );
@@ -566,10 +576,10 @@ public function methodFromItems(
566576 $ method = new MethodGenerator (
567577 'fromItems ' ,
568578 [
569- (new ParameterGenerator ($ argumentName , ($ this ->classNameFilter )($ argumentType )))->setVariadic (true ),
579+ (new ParameterGenerator (( $ this -> propertyNameFilter )( $ argumentName) , ($ this ->classNameFilter )($ argumentType )))->setVariadic (true ),
570580 ],
571581 MethodGenerator::FLAG_PUBLIC | MethodGenerator::FLAG_STATIC ,
572- new BodyGenerator ($ this ->parser , \sprintf ('return new self(...$%s); ' , $ argumentName ))
582+ new BodyGenerator ($ this ->parser , \sprintf ('return new self(...$%s); ' , ( $ this -> propertyNameFilter )( $ argumentName) ))
573583 );
574584 $ method ->setTyped ($ this ->typed );
575585 $ method ->setReturnType ('self ' );
0 commit comments