Skip to content

Commit 6825333

Browse files
committed
Merge branch 'php-8.0/generic-unused-parameter-add-support-constr-prop-prom' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents dc59530 + 529043f commit 6825333

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php

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

9292
foreach ($methodParams as $param) {
93+
if (isset($param['property_visibility']) === true) {
94+
// Ignore. Constructor property promotion.
95+
continue;
96+
}
97+
9398
$params[$param['name']] = $stackPtr;
9499
}
95100

src/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,16 @@ function moreParamFirst(Exception $foo, LogicException $bar) {
137137
function moreParamSecond(LogicException $bar, Exception $foo) {
138138
return 'foobar' . $bar;
139139
}
140+
// phpcs:set Generic.CodeAnalysis.UnusedFunctionParameter ignoreTypeHints[]
141+
142+
class ConstructorPropertyPromotionNoContentInMethod {
143+
public function __construct(protected int $id) {}
144+
}
145+
146+
class ConstructorPropertyPromotionWithContentInMethod {
147+
public function __construct(protected int $id, $toggle = true) {
148+
if ($toggle === true) {
149+
doSomething();
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)