Skip to content

Commit 033e975

Browse files
committed
Merge branch 'feature/3778-squiz-lowercasephpfunctions-bugfix' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 1807f76 + 4d2d3d4 commit 033e975

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public function process(File $phpcsFile, $stackPtr)
163163
return;
164164
}
165165

166+
if (empty($tokens[$stackPtr]['nested_attributes']) === false) {
167+
// Class instantiation in attribute, not function call.
168+
return;
169+
}
170+
166171
$function = strtolower($tokens[$stackPtr]['content']);
167172
$pattern = null;
168173

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ function mymodule_form_callback(SizeOf $sizeof) {
5555
}
5656

5757
$size = $class?->sizeof($array);
58+
59+
#[SizeOf(10)]
60+
function doSomething() {}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function process(File $phpcsFile, $stackPtr)
7575
}
7676

7777
// Make sure this is a function call or a use statement.
78+
if (empty($tokens[$stackPtr]['nested_attributes']) === false) {
79+
// Class instantiation in attribute, not function call.
80+
return;
81+
}
82+
7883
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
7984
if ($next === false) {
8085
// Not a function call.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
error_log('test');
33
print_r($array);
44
var_dump($array);
5-
?>
5+
6+
#[Var_Dump(10)]
7+
function debugMe() {}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ $callToNamespacedFunction = namespace\STR_REPEAT($a, 2); // Could potentially be
4141
$filePath = new \File($path);
4242

4343
$count = $object?->Count();
44+
45+
class AttributesShouldBeIgnored
46+
{
47+
#[Putenv('FOO', 'foo')]
48+
public function foo(): void
49+
{}
50+
}

src/Standards/Squiz/Tests/PHP/LowercasePHPFunctionsUnitTest.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,10 @@ $callToNamespacedFunction = namespace\STR_REPEAT($a, 2); // Could potentially be
4141
$filePath = new \File($path);
4242

4343
$count = $object?->Count();
44+
45+
class AttributesShouldBeIgnored
46+
{
47+
#[Putenv('FOO', 'foo')]
48+
public function foo(): void
49+
{}
50+
}

0 commit comments

Comments
 (0)