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

Generic/OpeningFunctionBraceKernighanRitchie: fix error position #3871

Closed jrfnl closed 9 months ago

jrfnl commented 1 year ago

Description

The SpaceBeforeBrace error code is about the space before the scope opener, but was being thrown on the parenthesis closer preceding it, which could be confusing when there is a type declaration between the two.

Fixed now.

I haven't added a test as no meaningful test can be added as the error "column" is not part of the test logic.

To see the issue run the following command over the below code snippet:

phpcs test.php --standard=Generic --sniffs=Generic.Functions.OpeningFunctionBraceKernighanRitchie --report=code
function foo( $param_a, $param_b ): Type       {}
//                       The space here   ^   was originally flagged on the close parens, not the open brace.

Suggested changelog entry

N/A

Types of changes

jrfnl commented 9 months ago

Closing as replaced by https://github.com/PHPCSStandards/PHP_CodeSniffer/pull/82