Skip to content

Commit fb90c4f

Browse files
committed
Generic/MultipleStatementAlignment: fix fatal error
In certain cases, it was possible for the `$expected` padding to become less than zero, leading to the following fatal error during fixing: `str_repeat(): Second argument has to be greater than or equal to 0 in phpcs/src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php on line 293` This PR fixes that. Includes unit tests.
1 parent be6850f commit fb90c4f

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

src/Standards/Generic/Sniffs/Formatting/MultipleStatementAlignmentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function checkAlignment($phpcsFile, $stackPtr)
180180
$assignColumn = ($varEnd + 1);
181181
} else {
182182
$padding = ($assignments[$prevAssign]['assign_col'] - $varEnd + $assignments[$prevAssign]['assign_len'] - $assignLen);
183-
if ($padding === 0) {
183+
if ($padding <= 0) {
184184
$padding = 1;
185185
}
186186

src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ function() {
108108
if (condition)
109109
foo = .4
110110
}
111+
112+
x = x << y;
113+
x <<= y;
114+
x = x >> y;
115+
x >>= y;

src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.js.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ function() {
108108
if (condition)
109109
foo = .4
110110
}
111+
112+
x = x << y;
113+
x <<= y;
114+
x = x >> y;
115+
x >>= y;

src/Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ public function getWarningList($testFile='MultipleStatementAlignmentUnitTest.inc
107107
85 => 1,
108108
86 => 1,
109109
100 => 1,
110+
112 => 1,
111+
113 => 1,
112+
114 => 1,
110113
];
111114
break;
112115
default:

0 commit comments

Comments
 (0)