Skip to content

Commit 32e74e4

Browse files
committed
Merge branch 'feature/squiz-operator-spacing-prevent-adding-superfluous-whitespace' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 8c31253 + db24dcc commit 32e74e4

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ public function process(File $phpcsFile, $stackPtr)
109109
}
110110
}//end if
111111

112+
$hasNext = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
113+
if ($hasNext === false) {
114+
// Live coding/parse error at end of file.
115+
return;
116+
}
117+
112118
// Check there is one space after the & operator.
113119
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
114120
$error = 'Expected 1 space after "&" operator; 0 found';
@@ -191,7 +197,9 @@ public function process(File $phpcsFile, $stackPtr)
191197
}//end if
192198
}//end if
193199

194-
if (isset($tokens[($stackPtr + 1)]) === false) {
200+
$hasNext = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
201+
if ($hasNext === false) {
202+
// Live coding/parse error at end of file.
195203
return;
196204
}
197205

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,6 @@ $a = ($a)instanceof$b;
267267

268268
// phpcs:set Squiz.WhiteSpace.OperatorSpacing ignoreSpacingBeforeAssignments false
269269
$a = 3;
270+
271+
/* Intentional parse error. This has to be the last test in the file. */
272+
$a = 10 +

src/Standards/Squiz/Tests/WhiteSpace/OperatorSpacingUnitTest.inc.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,6 @@ $a = ($a) instanceof $b;
261261

262262
// phpcs:set Squiz.WhiteSpace.OperatorSpacing ignoreSpacingBeforeAssignments false
263263
$a = 3;
264+
265+
/* Intentional parse error. This has to be the last test in the file. */
266+
$a = 10 +

0 commit comments

Comments
 (0)