Skip to content

Commit

Permalink
NativeFunctionInvocationFixer - namespaced strict to remove backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Jan 2, 2019
1 parent f312223 commit 1241bda
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function isRisky()
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
if ('all' === $this->configuration['scope']) {
$this->fixFunctionCalls($tokens, $this->functionFilter, 0, \count($tokens) - 1);
$this->fixFunctionCalls($tokens, $this->functionFilter, 0, \count($tokens) - 1, false);

return;
}
Expand All @@ -192,11 +192,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
// 'scope' is 'namespaced' here
/** @var NamespaceAnalysis $namespace */
foreach (array_reverse($namespaces) as $namespace) {
if ('' === $namespace->getFullName()) {
continue;
}

$this->fixFunctionCalls($tokens, $this->functionFilter, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex());
$this->fixFunctionCalls($tokens, $this->functionFilter, $namespace->getScopeStartIndex(), $namespace->getScopeEndIndex(), '' === $namespace->getFullName());
}
}

Expand Down Expand Up @@ -264,8 +260,9 @@ protected function createConfigurationDefinition()
* @param callable $functionFilter
* @param int $start
* @param int $end
* @param bool $tryToRemove
*/
private function fixFunctionCalls(Tokens $tokens, callable $functionFilter, $start, $end)
private function fixFunctionCalls(Tokens $tokens, callable $functionFilter, $start, $end, $tryToRemove)
{
$functionsAnalyzer = new FunctionsAnalyzer();

Expand All @@ -277,8 +274,11 @@ private function fixFunctionCalls(Tokens $tokens, callable $functionFilter, $sta

$prevIndex = $tokens->getPrevMeaningfulToken($index);

if (!$functionFilter($tokens[$index]->getContent())) {
if ($this->configuration['strict'] && $tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
if (!$functionFilter($tokens[$index]->getContent()) || $tryToRemove) {
if (!$this->configuration['strict']) {
continue;
}
if ($tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
$tokens->clearTokenAndMergeSurroundingWhitespace($prevIndex);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,20 @@ public function & strlen($name) {
'strict' => true,
],
],
'scope namespaced and strict enabled' => [
'<?php
$a = not_compiler_optimized_function();
$b = intval($c);
',
'<?php
$a = \not_compiler_optimized_function();
$b = \intval($c);
',
[
'scope' => 'namespaced',
'strict' => true,
],
],
];
}

Expand Down

0 comments on commit 1241bda

Please sign in to comment.