|
6 | 6 | use PHP_CodeSniffer\Sniffs\Sniff;
|
7 | 7 | use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
|
8 | 8 | use SlevomatCodingStandard\Helpers\AnnotationHelper;
|
9 |
| -use SlevomatCodingStandard\Helpers\Attribute; |
10 | 9 | use SlevomatCodingStandard\Helpers\AttributeHelper;
|
11 | 10 | use SlevomatCodingStandard\Helpers\SuppressHelper;
|
12 |
| -use SlevomatCodingStandard\Helpers\TokenHelper; |
13 |
| -use function array_map; |
14 |
| -use function in_array; |
15 | 11 | use function sprintf;
|
16 | 12 | use function strtolower;
|
17 |
| -use const T_ATTRIBUTE; |
18 | 13 | use const T_DOC_COMMENT_OPEN_TAG;
|
19 | 14 |
|
20 | 15 | class DisallowMixedTypeHintSniff implements Sniff
|
@@ -48,7 +43,7 @@ public function process(File $phpcsFile, $docCommentOpenPointer): void
|
48 | 43 | return;
|
49 | 44 | }
|
50 | 45 |
|
51 |
| - if ($this->targetHasOverrideAttribute($phpcsFile, $docCommentOpenPointer)) { |
| 46 | + if (AttributeHelper::hasAttribute($phpcsFile, $docCommentOpenPointer, '\Override')) { |
52 | 47 | return;
|
53 | 48 | }
|
54 | 49 |
|
@@ -78,21 +73,4 @@ private function getSniffName(string $sniffName): string
|
78 | 73 | return sprintf('%s.%s', self::NAME, $sniffName);
|
79 | 74 | }
|
80 | 75 |
|
81 |
| - private function targetHasOverrideAttribute(File $phpcsFile, int $docCommentOpenPointer): bool |
82 |
| - { |
83 |
| - $tokens = $phpcsFile->getTokens(); |
84 |
| - $nextPointer = TokenHelper::findNextEffective($phpcsFile, $docCommentOpenPointer + 1); |
85 |
| - |
86 |
| - if ($nextPointer === null || $tokens[$nextPointer]['code'] !== T_ATTRIBUTE) { |
87 |
| - return false; |
88 |
| - } |
89 |
| - |
90 |
| - $attributeNames = array_map( |
91 |
| - static fn (Attribute $name): string => $name->getFullyQualifiedName(), |
92 |
| - AttributeHelper::getAttributes($phpcsFile, $nextPointer), |
93 |
| - ); |
94 |
| - |
95 |
| - return in_array('\Override', $attributeNames, true); |
96 |
| - } |
97 |
| - |
98 | 76 | }
|
0 commit comments