Skip to content

Commit

Permalink
ExplicitStringVariableFixer - fix array handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan committed Jul 24, 2018
1 parent 1c9553a commit 4c2222c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Fixer/StringNotation/ExplicitStringVariableFixer.php
Expand Up @@ -95,6 +95,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
foreach ($variableTokens as $variablePartIndex => $variablePartToken) {
if ($variablePartToken->isGivenKind(T_NUM_STRING)) {
$tokens[$variablePartIndex] = new Token([T_LNUMBER, $variablePartToken->getContent()]);

continue;
}

if ($variablePartToken->isGivenKind(T_STRING) && $tokens[$variablePartIndex + 1]->equals(']')) {
$tokens[$variablePartIndex] = new Token([T_CONSTANT_ENCAPSED_STRING, "'".$variablePartToken->getContent()."'"]);
}
}

Expand Down
Expand Up @@ -114,8 +114,8 @@ public function provideTestFixCases()
'<?php $a = "My name is $array[1] !";',
],
[
'<?php $a = "My name is {$array[MY_CONSTANT]} !";',
'<?php $a = "My name is $array[MY_CONSTANT] !";',
'<?php $a = "My name is {$array[\'foo\']} !";',
'<?php $a = "My name is $array[foo] !";',
],
[
'<?php $a = "Closure not allowed ${closure}() text";',
Expand Down

0 comments on commit 4c2222c

Please sign in to comment.