Skip to content

Commit f0146d7

Browse files
authored
Ignore function call arguments on static declarations processing (sirbrillig#273)
1 parent 567221e commit f0146d7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Tests/VariableAnalysisSniff/fixtures/ClassWithMembersFixture.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,11 @@ public function baz3($param) { // Unused variable $param
175175
return 'foobar';
176176
}
177177
}
178+
179+
class ClassWithStaticCreateMethod {
180+
181+
public static function createStatic($value) {
182+
return new static($value);
183+
}
184+
185+
}

Tests/VariableAnalysisSniff/fixtures/FunctionWithClosureFixture.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,10 @@ function function_with_fully_qualified_type_argument_in_closure($items, $item_id
9494
return $line_item->item_id === $item_id;
9595
});
9696
}
97+
98+
function function_with_static_closure() {
99+
$params = array();
100+
array_map(static function ($inner_param) {
101+
echo $inner_param;
102+
}, $params);
103+
}

VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,12 @@ protected function processVariableAsStaticDeclaration(File $phpcsFile, $stackPtr
13331333
return false;
13341334
}
13351335

1336+
// Is the token inside a function call? If so, this is not a static
1337+
// declaration.
1338+
if (Helpers::isTokenInsideFunctionCallArgument($phpcsFile, $stackPtr)) {
1339+
return false;
1340+
}
1341+
13361342
// Is the keyword a late static binding? If so, this isn't the static
13371343
// keyword we're looking for, but since static:: isn't allowed in a
13381344
// compile-time constant, we also know we can't be part of a static

0 commit comments

Comments
 (0)