@@ -55,6 +55,7 @@ class AttributeNodeVisitor extends NodeVisitorAbstract
55
55
private const ARGS_TWO_WITH_TYPE = 'two with type ' ;
56
56
private const ARGS_MANY_IN_USE = "many in use " ;
57
57
private const ARGS_MANY_WITH_NAME = "many with name " ;
58
+ private const ARGS_MANY_WITH_NAME_WITH_PREFIX = "many with name with prefix " ;
58
59
private const ARGS_MANY_IN_TYPE = "many in type " ;
59
60
private const ARGS_MANY_WITHOUT_NAME = "many without name " ;
60
61
private const ARGS_MANY_WITHOUT_NAME_AND_PREFIX = "many without name and prexif " ;
@@ -246,6 +247,8 @@ class AttributeNodeVisitor extends NodeVisitorAbstract
246
247
],
247
248
Property::class => [
248
249
Stmt \Class_::class => 'property ' ,
250
+ Stmt \Interface_::class => 'property ' ,
251
+ Stmt \Trait_::class => 'property ' ,
249
252
Stmt \Property::class => 'var ' ,
250
253
],
251
254
PropertyRead::class => [
@@ -301,13 +304,13 @@ class AttributeNodeVisitor extends NodeVisitorAbstract
301
304
302
305
private const ARGUMENTS_PER_ATTRIBUTE = [
303
306
Assert::class => [
304
- 'all ' => self ::ARGS_MANY_WITH_NAME ,
307
+ 'all ' => self ::ARGS_MANY_WITH_NAME_WITH_PREFIX ,
305
308
],
306
309
AssertIfFalse::class => [
307
- 'all ' => self ::ARGS_MANY_WITH_NAME ,
310
+ 'all ' => self ::ARGS_MANY_WITH_NAME_WITH_PREFIX ,
308
311
],
309
312
AssertIfTrue::class => [
310
- 'all ' => self ::ARGS_MANY_WITH_NAME ,
313
+ 'all ' => self ::ARGS_MANY_WITH_NAME_WITH_PREFIX ,
311
314
],
312
315
DefineType::class => [
313
316
'all ' => self ::ARGS_MANY_IN_TYPE ,
@@ -344,6 +347,8 @@ class AttributeNodeVisitor extends NodeVisitorAbstract
344
347
],
345
348
Property::class => [
346
349
Stmt \Class_::class => self ::ARGS_MANY_WITH_NAME ,
350
+ Stmt \Interface_::class => self ::ARGS_MANY_WITH_NAME ,
351
+ Stmt \Trait_::class => self ::ARGS_MANY_WITH_NAME ,
347
352
Stmt \Property::class => self ::ARGS_ONE ,
348
353
],
349
354
PropertyRead::class => [
@@ -425,9 +430,9 @@ public function enterNode(Node $node)
425
430
426
431
$ this ->initPositions ();
427
432
428
- foreach ($ attributeGroups as $ attributeGroup ) {
433
+ foreach ($ attributeGroups as $ groupKey => $ attributeGroup ) {
429
434
$ attributes = $ attributeGroup ->attrs ;
430
- foreach ($ attributes as $ attribute ) {
435
+ foreach ($ attributes as $ key => $ attribute ) {
431
436
$ attributeName = $ attribute ->name ->toString ();
432
437
$ attributeName = self ::SHORT_NAME_TO_FQN [$ attributeName ] ?? $ attributeName ;
433
438
if (
@@ -473,7 +478,7 @@ public function enterNode(Node $node)
473
478
$ nodeType ,
474
479
$ attributeName ,
475
480
$ args [0 ],
476
- prefix: $ this -> toolType === self ::TOOL_PSALM ? $ this -> toolType : null
481
+ prefix: self ::TOOL_PSALM
477
482
);
478
483
} else {
479
484
$ tagsToAdd [] = $ this ->createTag ($ nodeType , $ attributeName );
@@ -492,6 +497,12 @@ public function enterNode(Node $node)
492
497
$ tagCreated = true ;
493
498
}
494
499
break ;
500
+ case self ::ARGS_MANY_WITH_NAME_WITH_PREFIX :
501
+ foreach ($ args as $ arg ) {
502
+ $ tagsToAdd [] = $ this ->createTag ($ nodeType , $ attributeName , $ arg , useName: true , prefix: $ this ->toolType );
503
+ $ tagCreated = true ;
504
+ }
505
+ break ;
495
506
case self ::ARGS_MANY_WITHOUT_NAME :
496
507
foreach ($ args as $ arg ) {
497
508
$ tagsToAdd [] = $ this ->createTag ($ nodeType , $ attributeName , $ arg );
@@ -509,6 +520,7 @@ public function enterNode(Node $node)
509
520
if ($ arg ->value instanceof String_) {
510
521
$ useValue = $ arg ->value ->value ;
511
522
$ useTagsToAdd [$ useValue ] = $ this ->createTag ($ nodeType , $ attributeName , $ arg );
523
+ $ tagCreated = true ;
512
524
}
513
525
}
514
526
break ;
@@ -521,10 +533,17 @@ public function enterNode(Node $node)
521
533
}
522
534
if ($ tagCreated ) {
523
535
$ this ->updatePositions ($ attribute );
536
+ unset($ attributes [$ key ]);
524
537
}
525
538
}
526
539
}
540
+ if ($ attributes === []) {
541
+ unset($ attributeGroups [$ groupKey ]);
542
+ } else {
543
+ $ attributeGroup ->attrs = $ attributes ;
544
+ }
527
545
}
546
+ $ node ->attrGroups = $ attributeGroups ;
528
547
if ($ node instanceof Stmt \ClassMethod || $ node instanceof Stmt \Function_) {
529
548
$ tagsToAdd = array_merge ($ tagsToAdd , $ this ->getParamTagsFromParams ($ node ));
530
549
}
@@ -541,11 +560,11 @@ public function enterNode(Node $node)
541
560
private function createTag (
542
561
string $ nodeType ,
543
562
string $ attributeName ,
544
- Arg $ argument = null ,
545
- Arg $ of = null ,
563
+ ? Arg $ argument = null ,
564
+ ? Arg $ of = null ,
546
565
bool $ useName = false ,
547
- string $ nameToUse = null ,
548
- string $ prefix = null ,
566
+ ? string $ nameToUse = null ,
567
+ ? string $ prefix = null ,
549
568
bool $ prefixWithName = false
550
569
): string {
551
570
if (array_key_exists ($ nodeType , self ::ANNOTATION_PER_ATTRIBUTE [$ attributeName ])) {
0 commit comments