Skip to content

Commit

Permalink
bug #3944 ExplicitStringVariableFixer - fix array handling (gharlan)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.12 branch.

Discussion
----------

ExplicitStringVariableFixer - fix array handling

fixes #3943

Commits
-------

4c2222c ExplicitStringVariableFixer - fix array handling
  • Loading branch information
keradus committed Aug 10, 2018
2 parents 853f2ce + 4c2222c commit 33ff29c
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 33ff29c

Please sign in to comment.