Skip to content

Commit

Permalink
PSR12.ControlStructures.BooleanOperatorPlacement no longer complains …
Browse files Browse the repository at this point in the history
…when multiple expression appears on the same line (ref #2637)
  • Loading branch information
gsherwood committed Oct 9, 2019
1 parent e487b6e commit 52e9819
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
3 changes: 3 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- This check has been missing from these standards, but has now been implemented
-- When using the PEAR standard, the error code is PEAR.Functions.FunctionCallSignature.FirstArgumentPosition
-- When using PSR2 or PSR12, the error code is PSR2.Methods.FunctionCallSignature.FirstArgumentPosition
- PSR12.ControlStructures.BooleanOperatorPlacement no longer complains when multiple expression appears on the same line
-- Previously, boolean operators were enforce to appear at the start or end of lines only
-- Boolean operators can now appear in the middle of the line
- PSR12.Files.FileHeader no longer ignores comments preceding a use, namespace, or declare statement
- PSR12.Files.FileHeader now allows a hashbang line at the top of the file
- Fixed bug #2615 : Constant visibility false positive on non-class constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ public function process(File $phpcsFile, $stackPtr)

continue;
}

if ($position === null) {
$position = 'middle';
}

// Error here regardless as boolean operators need to be at start/end of line.
$msg = 'Boolean operators between conditions must be at the beginning or end of the line';
$phpcsFile->addError($msg, $next, 'FoundMiddle');

if ($position !== 'middle') {
$error = true;
}
} while ($operator !== false);

if ($error === false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ switch (
) {
// structure body
}

if (
($n > 0 && $n < 10)
|| ($n > 10 && $n < 20)
|| ($n > 20 && $n < 30)
) {
return $n;
}

if (
(
$expr1
&& $expr2
&& $expr3
&& $expr4
&& $expr5
&& $expr6
)
|| ($n > 100 && $n < 200)
|| ($n > 200 && $n < 300)
) {
return $n;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ switch (
) {
// structure body
}

if (
($n > 0 && $n < 10)
|| ($n > 10 && $n < 20)
|| ($n > 20 && $n < 30)
) {
return $n;
}

if (
(
$expr1
&& $expr2
&& $expr3
&& $expr4
&& $expr5
&& $expr6
)
|| ($n > 100 && $n < 200)
|| ($n > 200 && $n < 300)
) {
return $n;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ public function getErrorList()
{
return [
10 => 1,
12 => 1,
16 => 1,
18 => 1,
28 => 1,
29 => 1,
34 => 1,
37 => 3,
];

}//end getErrorList()
Expand Down

0 comments on commit 52e9819

Please sign in to comment.