Skip to content

Commit

Permalink
bug #6165 DeclareEqualNormalizeFixer - fix for declare having multipl…
Browse files Browse the repository at this point in the history
…e directives (kubawerlos)

This PR was squashed before being merged into the master branch (closes #6165).

Discussion
----------

DeclareEqualNormalizeFixer - fix for declare having multiple directives

One more edgy edge case found running [regression](#6152 (comment)).

Commits
-------

03f5eff DeclareEqualNormalizeFixer - fix for declare having multiple directives
  • Loading branch information
SpacePossum committed Dec 13, 2021
2 parents 7dd6206 + 03f5eff commit 38df50e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php
Expand Up @@ -88,9 +88,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
continue;
}

while (!$tokens[++$index]->equals('='));
$openParenthesisIndex = $tokens->getNextMeaningfulToken($index);
$closeParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesisIndex);

$this->{$callback}($tokens, $index);
for ($i = $closeParenthesisIndex; $i > $openParenthesisIndex; --$i) {
if ($tokens[$i]->equals('=')) {
$this->{$callback}($tokens, $i);
}
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php
Expand Up @@ -87,6 +87,16 @@ public function provideFixCases(): array
null,
['space' => 'none'],
],
'declare having multiple directives, single' => [
'<?php declare(strict_types=1, ticks=1);',
'<?php declare(strict_types = 1, ticks = 1);',
[],
],
'declare having multiple directives, none' => [
'<?php declare(strict_types = 1, ticks = 1);',
'<?php declare(strict_types=1, ticks=1);',
['space' => 'single'],
],
];
}

Expand Down

0 comments on commit 38df50e

Please sign in to comment.