diff --git a/config/sets/annotations-to-attributes.php b/config/sets/annotations-to-attributes.php index e4c6f802..5ea5003d 100644 --- a/config/sets/annotations-to-attributes.php +++ b/config/sets/annotations-to-attributes.php @@ -14,6 +14,11 @@ use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute; return static function (RectorConfig $rectorConfig): void { + // safety check, not to run on PHPUnit 9 and bellow where are no attributes + if (! class_exists('PHPUnit\Framework\Attributes\DataProvider')) { + return; + } + $rectorConfig->rules([ TicketAnnotationToAttributeRector::class, TestWithAnnotationToAttributeRector::class, diff --git a/rules-tests/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector/Fixture/external-provider-fqcn.php b/rules-tests/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector/Fixture/external-provider-fqcn.php new file mode 100644 index 00000000..b76711f1 --- /dev/null +++ b/rules-tests/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector/Fixture/external-provider-fqcn.php @@ -0,0 +1,24 @@ + diff --git a/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php b/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php index 59770217..b891c46c 100644 --- a/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php +++ b/rules/AnnotationsToAttributes/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php @@ -10,6 +10,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\Reflection\ClassReflection; +use PHPStan\Reflection\ReflectionProvider; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; @@ -35,6 +36,7 @@ public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly DocBlockUpdater $docBlockUpdater, private readonly PhpDocInfoFactory $phpDocInfoFactory, + private readonly ReflectionProvider $reflectionProvider, ) { } @@ -120,6 +122,11 @@ public function refactor(Node $node): ?Node return null; } + // safety check, no to upgrade phpunit annotations to soon + if (! $this->reflectionProvider->hasClass('PHPUnit\Framework\Attributes\DataProvider')) { + return null; + } + foreach ($desiredTagValueNodes as $desiredTagValueNode) { if (! $desiredTagValueNode->value instanceof GenericTagValueNode) { continue;