Skip to content

Commit 3a094b7

Browse files
committed
PHP 8.0 | Squiz/DisallowSizeFunctionsInLoops: allow for nullsafe object operator
Includes unit test.
1 parent 85f3521 commit 3a094b7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Standards/Squiz/Sniffs/PHP/DisallowSizeFunctionsInLoopsSniff.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public function process(File $phpcsFile, $stackPtr)
9595
$functionName = 'object.'.$functionName;
9696
} else {
9797
// Make sure it isn't a member var.
98-
if ($tokens[($i - 1)]['code'] === T_OBJECT_OPERATOR) {
98+
if ($tokens[($i - 1)]['code'] === T_OBJECT_OPERATOR
99+
|| $tokens[($i - 1)]['code'] === T_NULLSAFE_OBJECT_OPERATOR
100+
) {
99101
continue;
100102
}
101103

src/Standards/Squiz/Tests/PHP/DisallowSizeFunctionsInLoopsUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ do {
5555
} while($a->count);
5656

5757
for ($i = 0; $i < $a->count; $i++) {}
58-
?>
58+
for ($i = 0; $i < $a?->count; $i++) {}

0 commit comments

Comments
 (0)