Skip to content

[Documentation] PSR12 - Boolean Operator Placement #181

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<documentation title="Boolean Operator Placement">
<standard>
<![CDATA[
Boolean operators between conditions in control structures must always be at the beginning or at the end of the line, not a mix of both.

This rule applies to if/else conditions, while loops and switch/match statements.
]]>
</standard>
<code_comparison>
<code title="Valid: Boolean operator between conditions consistently at the beginning of the line.">
<![CDATA[
if (
$expr1
&& $expr2
&& ($expr3
|| $expr4)
&& $expr5
) {
// if body.
}
]]>
</code>
<code title="Invalid: Mix of boolean operators at the beginning and the end of the line.">
<![CDATA[
if (
$expr1 &&
($expr2 || $expr3)
&& $expr4
) {
// if body.
}
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Boolean operator between conditions consistently at the end of the line.">
<![CDATA[
if (
$expr1 ||
($expr2 || $expr3) &&
$expr4
) {
// if body.
}
]]>
</code>
<code title="Invalid: Mix of boolean operators at the beginning and the end of the line.">
<![CDATA[
match (
$expr1
&& $expr2 ||
$expr3
) {
// structure body.
};
]]>
</code>
</code_comparison>
</documentation>