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

Make FunctionCallSignatureSniff work when closing brace doesn't have to be placed on its own line #3848

Open
Daimona opened this issue Jul 1, 2023 · 0 comments

Comments

@Daimona
Copy link
Contributor

Daimona commented Jul 1, 2023

FunctionCallSignatureSniff assumes that the closing call parentheses is placed on its own line. If that's not the case, the CloseBracketLine issue is emitted. This can clearly be disabled in a custom standard, if wanted; however, the sniff also makes the same assumption elsewhere:

if ($tokens[$nextCode]['line'] === $tokens[$closeBracket]['line']) {
    // Closing brace needs to be indented to the same level
    // as the function call.
    $inArg          = false;
    $expectedIndent = ($foundFunctionIndent + $adjustment);
} else {
    $expectedIndent = ($foundFunctionIndent + $this->indent + $adjustment);
}

This means that if you disable CloseBracketLine and run PHPCS on the following code:

function foo() {
    $this->doSomething(
        $firstArg, $secondArg, $thirdArg );
}

it will still complain that the second call line is not indented correctly. In particular, since it contains the closing parentheses, PHPCS wants it to have the same indentation as the first call line, meaning it would consider this to be correct:

function foo() {
    $this->doSomething(
    $firstArg, $secondArg, $thirdArg );
}

Therefore, I'm asking if it would be possible to make the sniff work in a custom standard that does not require the closing parentheses to be on its own line. This could perhaps be a config option to the sniff; or maybe the if branch in the conditional above could be updated to check that the closing parentheses is the only thing on that line. However, this would need to account for arrays:

function foo() {
    $this->doSomething( [
        $firstArg, $secondArg, $thirdArg
    ] ); // This is correct; even if the ) is not alone, this line should have the same indentation as the opener (
}

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants