Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NoSpacesAfterFunctionNameFixer - do not remove space if the opening parenthesis part of an expression #7430

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that yields' keys would make test cases more descriptive and easier to grasp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes, sometimes you want to have a different example of the same issue and there is dilemma of putting it in one code chunk or to split into a few smaller code samples.

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 [
kubawerlos marked this conversation as resolved.
Show resolved Hide resolved
'<?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