Repository navigation
Add OperatorPosition sniff for wrapped boolean, ternary, coalesce and arithmetic operators - #91
Merged
Merged
Conversation
This was referenced Oct 25, 2026
Universal.Operators.ConcatPosition only covers `.`. The new PhpCollective.Operators.OperatorPosition sniff applies the same rule to `&&`, `||`, `and`, `or`, `xor`, `??`, the ternary `?` and `:` (with `?:` moved as one unit) and binary `+ - * / % **`: when the operator ends a line and the expression continues on the next, it moves to the start of the continuation line. Unary plus/minus, return-type and case colons, nullable `?` and operators followed by a comment (reported, not fixed) are left alone. The repository's own sources are updated to pass the new rule. On the 206 files of the cakephp PER-CS PR, the fixer output matches the PR's php-cs-fixer result for 171 of the 175 wrapped non-concat expressions. The rest are an `=` moved to the line start (not covered), a `phpcs:disable` block and a `??` that stood alone on its own line.
dereuromark
force-pushed
the
operator-position
branch
from
October 25, 2026 14:13
5b7be1d to
3a22580
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #87
Adds
PhpCollective.Operators.OperatorPositionand enables it in the PhpCollective ruleset next toUniversal.Operators.ConcatPosition.Covered:
&&,||,and,or,xor,??, ternary?/:(?:moves as one unit, also when split as?newline:), and binary+ - * / % **. Not touched: unary+/-, return-type andcasecolons, nullable?,=and other assignment operators, comparison and bitwise operators. With a comment between the operator and the next token, the error is reported asIncorrectWithCommentand not fixed. An operator standing alone on its own line is left as is.This changes what the standard enforces: projects with operators at the end of a line get new, auto-fixable errors. The repo's own sources are updated in this PR (5 files).
Checked against the 206 files of cakephp/cakephp#19740: the fixer output matches the PR's php-cs-fixer (
@PER-CS3x0) result for 171 of 175 wrapped non-concat expressions. The four others are an=moved to the line start, aphpcs:disableblock and a??alone on its own line, all out of scope.