Skip to content

Commit 1b07f5d

Browse files
committed
Generic/ForbiddenFunctions: improve comment tolerance
Includes some updated tests to cover this change.
1 parent 7be3761 commit 1b07f5d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function process(File $phpcsFile, $stackPtr)
142142
T_IMPLEMENTS => true,
143143
];
144144

145-
$prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
145+
$prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
146146

147147
if (isset($ignore[$tokens[$prevToken]['code']]) === true) {
148148
// Not a call to a PHP function.

src/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class RightSideVisTest {
4848
}
4949

5050
namespace Something\sizeof;
51-
$var = new Sizeof();
51+
$var = new /*comment*/ Sizeof();
5252
class SizeOf implements Something {}
5353

5454
function mymodule_form_callback(SizeOf $sizeof) {
@@ -58,3 +58,5 @@ $size = $class?->sizeof($array);
5858

5959
#[SizeOf(10)]
6060
function doSomething() {}
61+
62+
$size = sizeof /*comment*/ ($array);

src/Standards/Generic/Tests/PHP/ForbiddenFunctionsUnitTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ final class ForbiddenFunctionsUnitTest extends AbstractSniffUnitTest
3131
public function getErrorList()
3232
{
3333
$errors = [
34-
2 => 1,
35-
4 => 1,
36-
6 => 1,
34+
2 => 1,
35+
4 => 1,
36+
6 => 1,
37+
62 => 1,
3738
];
3839

3940
return $errors;

0 commit comments

Comments
 (0)