squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

Squiz.Functions.MultiLineFunctionDeclaration.SpaceBeforeOpenBrace allows newlines in between closing parenthesis and opening brace. #3845

Closed austinderrick closed 1 year ago

austinderrick commented 1 year ago

Describe the bug

Squiz.Functions.MultiLineFunctionDeclaration.SpaceBeforeOpenBrace allows newlines in between closing parenthesis and opening brace. I believe this rule should require the closing parenthesis and opening brace to be on the same line.

Code sample

Expected to Pass:

    public static function hasUsername(
        $managedInstanceURL,
        $apiKey,
        $username,
        $useCache = true
    ) {

Passes, but shouldn't:

    public static function hasUsername(
        $managedInstanceURL,
        $apiKey,
        $username,
        $useCache = true
    )
    {

Versions (please complete the following information)

Operating System MacOS 13.4
PHP version 8.0
PHP_CodeSniffer version 3.7.2 (stable) by Squiz (http://www.squiz.net)
Standard Squiz
Install type PHAR

Please confirm:

jrfnl commented 1 year ago

@austinderrick I cannot reproduce your issue.

When I run the sniff against your example code, I get the following error, which sounds to me exactly what you are looking for:

 | ERROR | [x] The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
 |       |     (Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace)

I suspect the above error code may be excluded from within your custom ruleset ?

austinderrick commented 1 year ago

Ope, you're correct. I had a silly mistake in my ruleset. Thanks for helping me find it.