Skip to content

Commit

Permalink
bug: FunctionsAnalyzer - fix detecting global function (#6792)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Feb 26, 2023
1 parent 8f4de80 commit cc6dea3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Tokenizer/Analyzer/FunctionsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public function isGlobalFunctionCall(Tokens $tokens, int $index): bool
return false;
}

if ($previousIsNamespaceSeparator) {
return true;
}

if ($tokens[$tokens->getNextMeaningfulToken($nextIndex)]->isGivenKind(CT::T_FIRST_CLASS_CALLABLE)) {
return false;
}

if ($previousIsNamespaceSeparator) {
return true;
}

if ($tokens->isChanged() || $tokens->getCodeHash() !== $this->functionsAnalysis['tokens']) {
$this->buildFunctionsAnalysis($tokens);
}
Expand Down
21 changes: 21 additions & 0 deletions tests/Fixer/LanguageConstruct/IsNullFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,25 @@ public static function provideFixCases(): array
],
];
}

/**
* @dataProvider provideFix81Cases
*
* @requires PHP 8.1
*/
public function testFix81(string $expected, ?string $input = null): void
{
$this->doTest($expected, $input);
}

public static function provideFix81Cases(): iterable
{
yield 'first-class callable' => [
'<?php array_filter([], is_null(...));',
];

yield 'first-class callable with leading slash' => [
'<?php array_filter([], \is_null(...));',
];
}
}
1 change: 1 addition & 0 deletions tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public static function provideIsGlobalFunctionCallPhp81Cases(): iterable
[],
'<?php
strlen(...);
\strlen(...);
$closure(...);
$invokableObject(...);
$obj->method(...);
Expand Down

0 comments on commit cc6dea3

Please sign in to comment.