Skip to content

Commit

Permalink
[CodeQuality] Use existing PhpAttributeAnalyzer service instead of At…
Browse files Browse the repository at this point in the history
…tributeFinder 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
  • Loading branch information
samsonasik authored Oct 12, 2024
1 parent 385d423 commit 61016bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Class_\DynamicDocBlockPropertyToNativePropertyRector\Fixture;

use Rector\Tests\CodeQuality\Rector\Class_\DynamicDocBlockPropertyToNativePropertyRector\Source\SomeDependency;

/**
* @property SomeDependency $someDependency
*/
final class SkipNoAllowDynamicPropertiesAttribute
{
public function run(): void
{
$this->someDependency = new SomeDependency();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 61016bf

Please sign in to comment.