Skip to content

Commit

Permalink
fix: NoSpacesAfterFunctionNameFixer - do not remove space if the op…
Browse files Browse the repository at this point in the history
…ening parenthesis part of an expression (#7430)
  • Loading branch information
kubawerlos committed Nov 28, 2023
1 parent cee6945 commit 34d914c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getPriority(): int

public function isCandidate(Tokens $tokens): bool
{
return $tokens->isAnyTokenKindsFound(array_merge($this->getFunctionyTokenKinds(), [T_STRING]));
return $tokens->isAnyTokenKindsFound([T_STRING, ...$this->getFunctionyTokenKinds()]);
}

protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
Expand All @@ -73,7 +73,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$nextNonWhiteSpace = $tokens->getNextMeaningfulToken($endParenthesisIndex);
if (
null !== $nextNonWhiteSpace
&& $tokens[$nextNonWhiteSpace]->equals('?')
&& !$tokens[$nextNonWhiteSpace]->equals(';')
&& $tokens[$lastTokenIndex]->isGivenKind($languageConstructionTokens)
) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,55 @@ function TisMy ($p1)
'<?php $a()(1);',
'<?php $a () (1);',
];

yield [
'<?php
echo (function () {})();
echo ($propertyValue ? "TRUE" : "FALSE") . EOL;
echo(FUNCTION_1);
echo (EXPRESSION + CONST_1), CONST_2;
',
'<?php
echo (function () {})();
echo ($propertyValue ? "TRUE" : "FALSE") . EOL;
echo (FUNCTION_1);
echo (EXPRESSION + CONST_1), CONST_2;
',
];

yield [
'<?php
include(SOME_PATH_1);
include_once(SOME_PATH_2);
require(SOME_PATH_3);
require_once(SOME_PATH_4);
print(SOME_VALUE);
print(FIRST_HALF_OF_STRING_1 . SECOND_HALF_OF_STRING_1);
print((FIRST_HALF_OF_STRING_2) . (SECOND_HALF_OF_STRING_2));
',
'<?php
include (SOME_PATH_1);
include_once (SOME_PATH_2);
require (SOME_PATH_3);
require_once (SOME_PATH_4);
print (SOME_VALUE);
print (FIRST_HALF_OF_STRING_1 . SECOND_HALF_OF_STRING_1);
print ((FIRST_HALF_OF_STRING_2) . (SECOND_HALF_OF_STRING_2));
',
];

yield [
'<?php
include (DIR) . FILENAME_1;
include_once (DIR) . (FILENAME_2);
require (DIR) . FILENAME_3;
require_once (DIR) . (FILENAME_4);
print (FIRST_HALF_OF_STRING_1) . SECOND_HALF_OF_STRING_1;
print (FIRST_HALF_OF_STRING_2) . ((((SECOND_HALF_OF_STRING_2))));
print ((FIRST_HALF_OF_STRING_3)) . ((SECOND_HALF_OF_STRING_3));
print ((((FIRST_HALF_OF_STRING_4)))) . ((((SECOND_HALF_OF_STRING_4))));
',
];
}

/**
Expand Down

0 comments on commit 34d914c

Please sign in to comment.