Skip to content

Commit f80aeb3

Browse files
committed
Squiz/DisallowSizeFunctionsInLoops: fix sniff to work with the PHP 8 identifier tokens
Includes extra unit tests covering the change in so far it wasn't already covered.
1 parent 7a921cd commit f80aeb3

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function process(File $phpcsFile, $stackPtr)
6767
}
6868

6969
for ($i = ($start + 1); $i < $end; $i++) {
70-
if ($tokens[$i]['code'] === T_STRING
71-
&& isset($this->forbiddenFunctions[$tokens[$i]['content']]) === true
70+
if (($tokens[$i]['code'] === T_STRING || $tokens[$i]['code'] === T_NAME_FULLY_QUALIFIED)
71+
&& isset($this->forbiddenFunctions[ltrim($tokens[$i]['content'], '\\')]) === true
7272
) {
7373
$functionName = $tokens[$i]['content'];
7474

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ do {
5656

5757
for ($i = 0; $i < $a->count; $i++) {}
5858
for ($i = 0; $i < $a?->count; $i++) {}
59+
60+
for ($i = 0; $i < \sizeof($this->children); $i++) {}
61+
while ($i < \count($array)) {}
62+
do {
63+
} while ($i < \strlen($string));

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function getErrorList()
4343
40 => 1,
4444
44 => 1,
4545
46 => 1,
46+
60 => 1,
47+
61 => 1,
48+
63 => 1,
4649
];
4750

4851
}//end getErrorList()

0 commit comments

Comments
 (0)