16
16
use Knuckles \Scribe \Tags2Attributes \TagParsers \UrlParamTagParser ;
17
17
use PhpParser \Node ;
18
18
use PhpParser \Node \Attribute ;
19
+ use PhpParser \Node \Expr \ClassConstFetch ;
19
20
use PhpParser \Node \Name \FullyQualified ;
20
21
use PHPStan \PhpDocParser \Ast \Node as DocNode ;
21
22
use PhpParser \Node \AttributeGroup ;
@@ -241,6 +242,7 @@ private function processGenericTags(PhpDocInfo $phpDocInfo) : array
241
242
}
242
243
243
244
$ attributeClass = $ annotationToAttribute ->getAttributeClass ();
245
+
244
246
$ items = $ this ->getArgs (
245
247
$ tag , $ docNode ->value ?->value, $ phpDocInfo
246
248
);
@@ -249,6 +251,7 @@ private function processGenericTags(PhpDocInfo $phpDocInfo) : array
249
251
$ args = $ this ->attributeArrayNameInliner ->inlineArrayToArgs ($ args );
250
252
$ attribute = new Attribute ($ fullyQualified , $ args );
251
253
$ attributeGroups [] = new AttributeGroup ([$ attribute ]);
254
+
252
255
$ phpDocInfo ->markAsChanged ();
253
256
return PhpDocNodeTraverser::NODE_REMOVE ;
254
257
}
@@ -273,6 +276,19 @@ public function getArgs($tag, $tagContent, $phpDocInfo)
273
276
return $ arguments ;
274
277
};
275
278
279
+ $ convertClassNamesToConst = function ($ args ) {
280
+ foreach ($ args as $ key => $ value ) {
281
+ if (is_string ($ value ) && class_exists ($ value )) {
282
+ $ fullyQualified = new FullyQualified ($ value );
283
+ $ args [$ key ] = new ClassConstFetch ($ fullyQualified , 'class ' );
284
+ } else {
285
+ $ args [$ key ] = $ value ;
286
+ }
287
+ }
288
+
289
+ return $ args ;
290
+ };
291
+
276
292
return match (strtolower ($ tag )) {
277
293
'header ' => explode (' ' , $ tagContent ),
278
294
'urlparam ' => $ parseAndRemoveEmptyKeys (UrlParamTagParser::class),
@@ -282,10 +298,10 @@ public function getArgs($tag, $tagContent, $phpDocInfo)
282
298
283
299
'response ' => $ parseAndRemoveEmptyKeys (ResponseTagParser::class),
284
300
'responsefile ' => $ parseAndRemoveEmptyKeys (ResponseFileTagParser::class),
285
- 'apiresource ' => $ parseAndRemoveEmptyKeys (ApiResourceTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags ()),
286
- 'apiresourcecollection ' => $ parseAndRemoveEmptyKeys (ApiResourceTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags (), true ),
287
- 'transformer ' => $ parseAndRemoveEmptyKeys (TransformerTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags ()),
288
- 'transformercollection ' => $ parseAndRemoveEmptyKeys (TransformerTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags (), true ),
301
+ 'apiresource ' => $ convertClassNamesToConst ( $ parseAndRemoveEmptyKeys (ApiResourceTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags () )),
302
+ 'apiresourcecollection ' => $ convertClassNamesToConst ( $ parseAndRemoveEmptyKeys (ApiResourceTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags (), true ) ),
303
+ 'transformer ' => $ convertClassNamesToConst ( $ parseAndRemoveEmptyKeys (TransformerTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags () )),
304
+ 'transformercollection ' => $ convertClassNamesToConst ( $ parseAndRemoveEmptyKeys (TransformerTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags (), true ) ),
289
305
290
306
'subgroup ' => $ parseAndRemoveEmptyKeys (SubgroupTagParser::class, $ phpDocInfo ->getPhpDocNode ()->getTags ()),
291
307
};
0 commit comments