From 61016bf5307b804df5babb81db27cacbccb12efa Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 12 Oct 2024 23:33:01 +0700 Subject: [PATCH] [CodeQuality] Use existing PhpAttributeAnalyzer service instead of AttributeFinder from Doctrine package on DynamicDocBlockPropertyToNativePropertyRector (#6382) * [CodeQuality] Use existing PhpAttributeAnalyzer service instead of AttributeFinder from Doctrine package on DynamicDocBlockPropertyToNativePropertyRector * add fixture * add fixture * add fixture --- ...no_allow_dynamic_properties_attribute.php.inc | 16 ++++++++++++++++ ...micDocBlockPropertyToNativePropertyRector.php | 11 +++-------- 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector/Fixture/skip_no_allow_dynamic_properties_attribute.php.inc diff --git a/rules-tests/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector/Fixture/skip_no_allow_dynamic_properties_attribute.php.inc b/rules-tests/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector/Fixture/skip_no_allow_dynamic_properties_attribute.php.inc new file mode 100644 index 0000000000..b00462d750 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector/Fixture/skip_no_allow_dynamic_properties_attribute.php.inc @@ -0,0 +1,16 @@ +someDependency = new SomeDependency(); + } +} diff --git a/rules/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector.php b/rules/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector.php index 8aa13b19c7..e9859c2193 100644 --- a/rules/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector.php +++ b/rules/CodeQuality/Rector/Class_/DynamicDocBlockPropertyToNativePropertyRector.php @@ -5,7 +5,6 @@ namespace Rector\CodeQuality\Rector\Class_; use PhpParser\Node; -use PhpParser\Node\Attribute; use PhpParser\Node\Expr; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; @@ -17,7 +16,7 @@ use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\CodeQuality\NodeFactory\TypedPropertyFactory; use Rector\Comments\NodeDocBlock\DocBlockUpdater; -use Rector\Doctrine\NodeAnalyzer\AttributeFinder; +use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; @@ -33,7 +32,7 @@ final class DynamicDocBlockPropertyToNativePropertyRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( - private readonly AttributeFinder $attributeFinder, + private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer, private readonly PhpDocInfoFactory $phpDocInfoFactory, private readonly PhpDocTagRemover $phpDocTagRemover, private readonly DocBlockUpdater $docBlockUpdater, @@ -89,11 +88,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $allowDynamicPropertiesAttribute = $this->attributeFinder->findAttributeByClass( - $node, - 'AllowDynamicProperties' - ); - if (! $allowDynamicPropertiesAttribute instanceof Attribute) { + if (! $this->phpAttributeAnalyzer->hasPhpAttribute($node, 'AllowDynamicProperties')) { return null; }