@@ -63,9 +63,11 @@ public static function generate(string $name, string $namespace, string $classNa
63
63
'_MINUS_ ' ,
64
64
], $ propertyName );
65
65
$ propertyStmt = $ factory ->property ($ propertyName )->makePrivate ();
66
- $ docBlock = [];
66
+ $ propertyDocBlock = [];
67
+ $ methodDocBlock = [];
67
68
if (strlen ($ property ->description ) > 0 ) {
68
- $ docBlock [] = $ property ->description ;
69
+ $ propertyDocBlock [] = $ property ->description ;
70
+ $ methodDocBlock [] = $ property ->description ;
69
71
}
70
72
$ method = $ factory ->method ($ propertyName )->makePublic ()/*->setReturnType('string')*/ ->addStmt (
71
73
new Node \Stmt \Return_ (
@@ -78,10 +80,12 @@ public static function generate(string $name, string $namespace, string $classNa
78
80
if (is_string ($ property ->type )) {
79
81
if ($ property ->type === 'array ' && $ property ->items instanceof OpenAPiSchema) {
80
82
if (array_key_exists (spl_object_hash ($ property ->items ), $ schemaClassNameMap )) {
83
+ $ methodDocBlock [] = '@return array< \\' . $ namespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->items )] . '> ' ;
81
84
$ docBlock [] = '@var array< \\' . $ namespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->items )] . '> ' ;
82
85
$ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray( \\' . $ namespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->items )] . '::class) ' ;
83
86
} elseif ($ property ->items ->type === 'object ' ) {
84
87
yield from self ::generate ($ name . ':: ' . $ propertyName , $ namespace . '\\' . $ className , (new Convert ($ propertyName ))->toPascal (), $ property ->items , $ schemaClassNameMap );
88
+ $ methodDocBlock [] = '@return array< \\' . $ namespace . '\\' . $ className . '\\' . (new Convert ($ propertyName ))->toPascal () . '> ' ;
85
89
$ docBlock [] = '@var array< \\' . $ namespace . '\\' . $ className . '\\' . (new Convert ($ propertyName ))->toPascal () . '> ' ;
86
90
$ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\HydrateArray( \\' . $ namespace . '\\' . $ className . '\\' . (new Convert ($ propertyName ))->toPascal () . '::class) ' ;
87
91
}
@@ -112,18 +116,22 @@ public static function generate(string $name, string $namespace, string $classNa
112
116
$ fqcnn = '\\' . $ namespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property ->anyOf [0 ])];
113
117
$ propertyStmt ->setType ('? ' . $ fqcnn )->setDefault (null );
114
118
$ method ->setReturnType ('? ' . $ fqcnn );
115
- $ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
119
+ $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
116
120
}
117
121
118
122
if ($ property ->type === 'object ' && $ property instanceof OpenAPiSchema && array_key_exists (spl_object_hash ($ property ), $ schemaClassNameMap )) {
119
123
$ fqcnn = '\\' . $ namespace . '\\' . $ schemaClassNameMap [spl_object_hash ($ property )];
120
124
$ propertyStmt ->setType ('? ' . $ fqcnn )->setDefault (null );
121
125
$ method ->setReturnType ('? ' . $ fqcnn );
122
- $ docBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
126
+ $ propertyDocBlock [] = '@\WyriHaximus\Hydrator\Attribute\Hydrate( ' . $ fqcnn . '::class) ' ;
123
127
}
124
128
125
- if (count ($ docBlock ) > 0 ) {
126
- $ propertyStmt ->setDocComment ('/** ' . PHP_EOL . ' * ' . implode (PHP_EOL . ' * ' , $ docBlock ) . PHP_EOL .' */ ' );
129
+ if (count ($ propertyDocBlock ) > 0 ) {
130
+ $ propertyStmt ->setDocComment ('/** ' . PHP_EOL . ' * ' . implode (PHP_EOL . ' * ' , $ propertyDocBlock ) . PHP_EOL .' */ ' );
131
+ }
132
+
133
+ if (count ($ methodDocBlock ) > 0 ) {
134
+ $ method ->setDocComment ('/** ' . PHP_EOL . ' * ' . implode (PHP_EOL . ' * ' , $ methodDocBlock ) . PHP_EOL .' */ ' );
127
135
}
128
136
129
137
$ class ->addStmt ($ propertyStmt )->addStmt ($ method );
0 commit comments