Skip to content

Commit 840f08b

Browse files
[AnnotationToAttribute] Handle already in use on DataProviderAnnotationToAttributeRector (#523)
* [AnnotationToAttribute] Handle already in use on DataProviderAnnotationToAttributeRector * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <[email protected]>
1 parent db71441 commit 840f08b

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
4+
5+
use PHPUnit\Framework\Attributes\DataProvider;
6+
use PHPUnit\Framework\TestCase;
7+
8+
final class AlreadyInUse extends TestCase
9+
{
10+
/**
11+
* @dataProvider someMethod()
12+
*/
13+
public function test(): void
14+
{
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\PHPUnit\Tests\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\Fixture;
23+
24+
use PHPUnit\Framework\Attributes\DataProvider;
25+
use PHPUnit\Framework\TestCase;
26+
27+
final class AlreadyInUse extends TestCase
28+
{
29+
#[\PHPUnit\Framework\Attributes\DataProvider('@dataProvider')]
30+
public function test(): void
31+
{
32+
}
33+
}
34+
35+
?>

rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
1212
use PHPStan\Reflection\ClassReflection;
1313
use PHPStan\Reflection\ReflectionProvider;
14+
use Rector\BetterPhpDocParser\PhpDoc\DoctrineAnnotationTagValueNode;
1415
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
1516
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1617
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
@@ -132,11 +133,15 @@ public function refactor(Node $node): ?Node
132133
}
133134

134135
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
135-
if (! $desiredTagValueNode->value instanceof GenericTagValueNode) {
136+
if (! $desiredTagValueNode->value instanceof GenericTagValueNode && ! $desiredTagValueNode->value instanceof DoctrineAnnotationTagValueNode) {
136137
continue;
137138
}
138139

139-
$originalAttributeValue = $desiredTagValueNode->value->value;
140+
if ($desiredTagValueNode->value instanceof GenericTagValueNode) {
141+
$originalAttributeValue = $desiredTagValueNode->value->value;
142+
} else {
143+
$originalAttributeValue = $desiredTagValueNode->value->identifierTypeNode->name;
144+
}
140145

141146
$node->attrGroups[] = $this->createAttributeGroup(strtok($originalAttributeValue, " \t\n\r\0\x0B"));
142147

0 commit comments

Comments
 (0)