Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeclareEqualNormalizeFixer - fix for declare having multiple directives #6165

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Expand Up @@ -87,6 +87,11 @@ public function provideFixCases(): array
null,
['space' => 'none'],
],
'declare having multiple directives' => [
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
'<?php declare(strict_types=1, ticks=1);',
'<?php declare(strict_types = 1, ticks = 1);',
[],
],
];
}

Expand Down