Skip to content

Commit 52e9819

Browse files
committed
PSR12.ControlStructures.BooleanOperatorPlacement no longer complains when multiple expression appears on the same line (ref #2637)
1 parent e487b6e commit 52e9819

File tree

5 files changed

+49
-16
lines changed

5 files changed

+49
-16
lines changed

package.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
3434
-- This check has been missing from these standards, but has now been implemented
3535
-- When using the PEAR standard, the error code is PEAR.Functions.FunctionCallSignature.FirstArgumentPosition
3636
-- When using PSR2 or PSR12, the error code is PSR2.Methods.FunctionCallSignature.FirstArgumentPosition
37+
- PSR12.ControlStructures.BooleanOperatorPlacement no longer complains when multiple expression appears on the same line
38+
-- Previously, boolean operators were enforce to appear at the start or end of lines only
39+
-- Boolean operators can now appear in the middle of the line
3740
- PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
3841
- PSR12.Files.FileHeader now allows a hashbang line at the top of the file
3942
- Fixed bug #2615 : Constant visibility false positive on non-class constants

src/Standards/PSR12/Sniffs/ControlStructures/BooleanOperatorPlacementSniff.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,6 @@ public function process(File $phpcsFile, $stackPtr)
116116

117117
continue;
118118
}
119-
120-
if ($position === null) {
121-
$position = 'middle';
122-
}
123-
124-
// Error here regardless as boolean operators need to be at start/end of line.
125-
$msg = 'Boolean operators between conditions must be at the beginning or end of the line';
126-
$phpcsFile->addError($msg, $next, 'FoundMiddle');
127-
128-
if ($position !== 'middle') {
129-
$error = true;
130-
}
131119
} while ($operator !== false);
132120

133121
if ($error === false) {

src/Standards/PSR12/Tests/ControlStructures/BooleanOperatorPlacementUnitTest.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,26 @@ switch (
3939
) {
4040
// structure body
4141
}
42+
43+
if (
44+
($n > 0 && $n < 10)
45+
|| ($n > 10 && $n < 20)
46+
|| ($n > 20 && $n < 30)
47+
) {
48+
return $n;
49+
}
50+
51+
if (
52+
(
53+
$expr1
54+
&& $expr2
55+
&& $expr3
56+
&& $expr4
57+
&& $expr5
58+
&& $expr6
59+
)
60+
|| ($n > 100 && $n < 200)
61+
|| ($n > 200 && $n < 300)
62+
) {
63+
return $n;
64+
}

src/Standards/PSR12/Tests/ControlStructures/BooleanOperatorPlacementUnitTest.inc.fixed

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,26 @@ switch (
4545
) {
4646
// structure body
4747
}
48+
49+
if (
50+
($n > 0 && $n < 10)
51+
|| ($n > 10 && $n < 20)
52+
|| ($n > 20 && $n < 30)
53+
) {
54+
return $n;
55+
}
56+
57+
if (
58+
(
59+
$expr1
60+
&& $expr2
61+
&& $expr3
62+
&& $expr4
63+
&& $expr5
64+
&& $expr6
65+
)
66+
|| ($n > 100 && $n < 200)
67+
|| ($n > 200 && $n < 300)
68+
) {
69+
return $n;
70+
}

src/Standards/PSR12/Tests/ControlStructures/BooleanOperatorPlacementUnitTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,9 @@ public function getErrorList()
2727
{
2828
return [
2929
10 => 1,
30-
12 => 1,
3130
16 => 1,
32-
18 => 1,
3331
28 => 1,
34-
29 => 1,
3532
34 => 1,
36-
37 => 3,
3733
];
3834

3935
}//end getErrorList()

0 commit comments

Comments
 (0)