Skip to content

Commit

Permalink
TokensAnalyzer - fix isConstantInvocation
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan authored and keradus committed Aug 19, 2018
1 parent 0790602 commit 53b196c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Tokenizer/TokensAnalyzer.php
Expand Up @@ -355,6 +355,15 @@ public function isConstantInvocation($index)
}
}

// check for array in double quoted string: `"..$foo[bar].."`
if ($this->tokens[$prevIndex]->equals('[') && $this->tokens[$nextIndex]->equals(']')) {
$checkToken = $this->tokens[$this->tokens->getNextMeaningfulToken($nextIndex)];

if ($checkToken->equals('"') || $checkToken->isGivenKind([T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES, T_ENCAPSED_AND_WHITESPACE, T_VARIABLE])) {
return false;
}
}

// check for goto label
if ($this->tokens[$nextIndex]->equals(':') && $this->tokens[$prevIndex]->equalsAny([';', '}', [T_OPEN_TAG], [T_OPEN_TAG_WITH_ECHO]])) {
return false;
Expand Down
12 changes: 12 additions & 0 deletions tests/Tokenizer/TokensAnalyzerTest.php
Expand Up @@ -544,6 +544,10 @@ public function provideIsConstantInvocationCases()
'<?php echo FOO & $bar;',
[3 => true],
],
[
'<?php echo $foo[BAR];',
[5 => true],
],
[
'<?php echo FOO[BAR];',
[3 => true, 5 => true],
Expand Down Expand Up @@ -644,6 +648,14 @@ public function provideIsConstantInvocationCases()
'<?php try {} catch (FOO $e) {}',
[9 => false],
],
[
'<?php "$foo[BAR]";',
[4 => false],
],
[
'<?php "{$foo[BAR]}";',
[5 => true],
],
[
'<?php FOO: goto FOO;',
[1 => false, 6 => false],
Expand Down

0 comments on commit 53b196c

Please sign in to comment.