-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PHP 8.0] Avoid duplicating attributed annotations (#212)
- Loading branch information
1 parent
25821f6
commit 6888049
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...otationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/skip_already_added.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\Php80\Rector\Class_\DoctrineAnnotationClassToAttributeRector\FixtureShouldNotRemoveAnnotation; | ||
|
||
use Attribute; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
#[Attribute] | ||
final class SkipAlreadyAdded | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Php80\NodeAnalyzer; | ||
|
||
use PhpParser\Node\Param; | ||
use PhpParser\Node\Stmt\ClassLike; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
use PhpParser\Node\Stmt\Property; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
|
||
final class PhpAttributeAnalyzer | ||
{ | ||
public function __construct( | ||
private NodeNameResolver $nodeNameResolver | ||
) { | ||
} | ||
|
||
public function hasPhpAttribute(Property | ClassLike | ClassMethod | Param $node, string $attributeClass): bool | ||
{ | ||
foreach ($node->attrGroups as $attrGroup) { | ||
foreach ($attrGroup->attrs as $attribute) { | ||
if (! $this->nodeNameResolver->isName($attribute->name, $attributeClass)) { | ||
continue; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters