Skip to content

Commit

Permalink
Add fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed May 24, 2024
1 parent 6d2226f commit 88a78d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 11 additions & 4 deletions src/Fixer/AbstractPhpUnitFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,20 @@ private static function isPreventedByAttribute(Tokens $tokens, int $index, array
return false;
}

$attributeIndex = $tokens->getPrevMeaningfulToken($index);
if (!$tokens[$attributeIndex]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
$modifiers = [T_FINAL];
if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.2+ is required
$modifiers[] = T_READONLY;
}

do {
$index = $tokens->getPrevMeaningfulToken($index);
} while ($tokens[$index]->isGivenKind($modifiers));
if (!$tokens[$index]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) {
return false;
}
$attributeIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $attributeIndex);
$index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $index);

foreach (AttributeAnalyzer::collect($tokens, $attributeIndex) as $attributeAnalysis) {
foreach (AttributeAnalyzer::collect($tokens, $index) as $attributeAnalysis) {
foreach ($attributeAnalysis->getAttributes() as $attribute) {
if (\in_array(self::getFullyQualifiedName($tokens, $attribute['name']), $preventingAttributes, true)) {
return true;
Expand Down
4 changes: 0 additions & 4 deletions src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en
return; // don't add `@covers` annotation for abstract base classes
}

if (isset($modifiers['final'])) {
$classIndex = $tokens->getPrevMeaningfulToken($classIndex);
}

$this->ensureIsDocBlockWithAnnotation(
$tokens,
$classIndex,
Expand Down

0 comments on commit 88a78d4

Please sign in to comment.