Skip to content

Commit 53b196c

Browse files
gharlankeradus
authored andcommitted
TokensAnalyzer - fix isConstantInvocation
1 parent 0790602 commit 53b196c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Tokenizer/TokensAnalyzer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,15 @@ public function isConstantInvocation($index)
355355
}
356356
}
357357

358+
// check for array in double quoted string: `"..$foo[bar].."`
359+
if ($this->tokens[$prevIndex]->equals('[') && $this->tokens[$nextIndex]->equals(']')) {
360+
$checkToken = $this->tokens[$this->tokens->getNextMeaningfulToken($nextIndex)];
361+
362+
if ($checkToken->equals('"') || $checkToken->isGivenKind([T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES, T_ENCAPSED_AND_WHITESPACE, T_VARIABLE])) {
363+
return false;
364+
}
365+
}
366+
358367
// check for goto label
359368
if ($this->tokens[$nextIndex]->equals(':') && $this->tokens[$prevIndex]->equalsAny([';', '}', [T_OPEN_TAG], [T_OPEN_TAG_WITH_ECHO]])) {
360369
return false;

tests/Tokenizer/TokensAnalyzerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,10 @@ public function provideIsConstantInvocationCases()
544544
'<?php echo FOO & $bar;',
545545
[3 => true],
546546
],
547+
[
548+
'<?php echo $foo[BAR];',
549+
[5 => true],
550+
],
547551
[
548552
'<?php echo FOO[BAR];',
549553
[3 => true, 5 => true],
@@ -644,6 +648,14 @@ public function provideIsConstantInvocationCases()
644648
'<?php try {} catch (FOO $e) {}',
645649
[9 => false],
646650
],
651+
[
652+
'<?php "$foo[BAR]";',
653+
[4 => false],
654+
],
655+
[
656+
'<?php "{$foo[BAR]}";',
657+
[5 => true],
658+
],
647659
[
648660
'<?php FOO: goto FOO;',
649661
[1 => false, 6 => false],

0 commit comments

Comments
 (0)