Skip to content

Commit

Permalink
ExplicitStringVariableFixer - variables pair if one is already explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Nov 26, 2019
1 parent 461b676 commit 93efab5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Fixer/StringNotation/ExplicitStringVariableFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$nextIndex = $index + 1;
$squareBracketCount = 0;
while (!$this->isStringPartToken($tokens[$nextIndex])) {
if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
if ($tokens[$nextIndex]->isGivenKind(T_CURLY_OPEN)) {
$nextIndex = $tokens->getNextTokenOfKind($nextIndex, [[CT::T_CURLY_CLOSE]]);
} elseif ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
$distinctVariableIndex = $nextIndex;
$variableTokens[$distinctVariableIndex] = [
'tokens' => [$nextIndex => $tokens[$nextIndex]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ public function provideTestFixCases()
'<?php $mobileNumberVisible = "***-***-{$last4Digits[0]}{$last4Digits[1]}-{$last4Digits[2]}{$last4Digits[3]}";',
'<?php $mobileNumberVisible = "***-***-$last4Digits[0]$last4Digits[1]-$last4Digits[2]$last4Digits[3]";',
],
[
'<?php $pair = "${foo} {$bar[0]}";',
'<?php $pair = "$foo {$bar[0]}";',
],
[
'<?php $pair = "${foo}{$bar[0]}";',
'<?php $pair = "$foo{$bar[0]}";',
],
];
}

Expand Down

0 comments on commit 93efab5

Please sign in to comment.