Skip to content

Commit

Permalink
bug #3910 FunctionsAnalyzer - fix isGlobalFunctionCall (gharlan)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.12 branch (closes #3910).

Discussion
----------

FunctionsAnalyzer - fix isGlobalFunctionCall

Commits
-------

c9849f8 FunctionsAnalyzer - fix isGlobalFunctionCall
  • Loading branch information
keradus committed Jul 20, 2018
2 parents 0790602 + c9849f8 commit e576dc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Tokenizer/Analyzer/FunctionsAnalyzer.php
Expand Up @@ -14,6 +14,7 @@

use PhpCsFixer\Tokenizer\Analyzer\Analysis\ArgumentAnalysis;
use PhpCsFixer\Tokenizer\Analyzer\Analysis\TypeAnalysis;
use PhpCsFixer\Tokenizer\CT;
use PhpCsFixer\Tokenizer\Tokens;

/**
Expand All @@ -40,7 +41,7 @@ public function isGlobalFunctionCall(Tokens $tokens, $index)

$nextIndex = $tokens->getNextMeaningfulToken($index);

return !$tokens[$prevIndex]->isGivenKind([T_DOUBLE_COLON, T_FUNCTION, T_NEW, T_OBJECT_OPERATOR, T_STRING])
return !$tokens[$prevIndex]->isGivenKind([T_DOUBLE_COLON, T_FUNCTION, CT::T_NAMESPACE_OPERATOR, T_NEW, T_OBJECT_OPERATOR, CT::T_RETURN_REF, T_STRING])
&& $tokens[$nextIndex]->equals('(');
}

Expand Down
12 changes: 11 additions & 1 deletion tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php
Expand Up @@ -97,7 +97,17 @@ public function provideIsGlobalFunctionCallCases()
],
[
false,
'<?php function foo() {};',
'<?php function foo() {}',
3,
],
[
false,
'<?php function & foo() {}',
5,
],
[
false,
'<?php namespace\foo("bar");',
3,
],
];
Expand Down

0 comments on commit e576dc9

Please sign in to comment.