File tree Expand file tree Collapse file tree
rules-tests/DeadCode/Rector/MethodCall/RemoveNullArgOnNullDefaultParamRector/Fixture
rules/DeadCode/NodeAnalyzer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \DeadCode \Rector \MethodCall \RemoveNullArgOnNullDefaultParamRector \Fixture ;
6+
7+ /**
8+ * @see https://3v4l.org/RCVaU#v8.3.9 vs https://3v4l.org/6DSlE#v8.3.9
9+ */
10+ final class SkipWithUseOfFuncNumArgs
11+ {
12+ private $ b = 1 ;
13+
14+ public function set ($ a , $ b = null )
15+ {
16+ if (func_num_args () > 1 ) {
17+ $ this ->b = $ b ;
18+ }
19+ }
20+
21+ public function get ()
22+ {
23+ $ this ->set (1 , null );
24+ return $ this ->b ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1212use PHPStan \Reflection \MethodReflection ;
1313use PHPStan \Reflection \ParametersAcceptorSelector ;
1414use PHPStan \Type \NullType ;
15+ use Rector \NodeAnalyzer \VariadicAnalyzer ;
1516use Rector \Reflection \ReflectionResolver ;
1617
1718final readonly class CallLikeParamDefaultResolver
1819{
1920 public function __construct (
2021 private ReflectionResolver $ reflectionResolver ,
22+ private VariadicAnalyzer $ variadicAnalyzer ,
2123 ) {
2224 }
2325
@@ -38,6 +40,10 @@ public function resolveNullPositions(MethodCall|StaticCall|New_|FuncCall $callLi
3840 }
3941 }
4042
43+ if ($ this ->variadicAnalyzer ->hasVariadicParameters ($ callLike )) {
44+ return [];
45+ }
46+
4147 $ nullPositions = [];
4248
4349 $ extendedParametersAcceptor = ParametersAcceptorSelector ::combineAcceptors ($ reflection ->getVariants ());
Original file line number Diff line number Diff line change 66
77use PhpParser \Node \Expr \FuncCall ;
88use PhpParser \Node \Expr \MethodCall ;
9+ use PhpParser \Node \Expr \New_ ;
910use PhpParser \Node \Expr \StaticCall ;
1011use PHPStan \Reflection \FunctionReflection ;
1112use PHPStan \Reflection \MethodReflection ;
@@ -18,7 +19,7 @@ public function __construct(
1819 ) {
1920 }
2021
21- public function hasVariadicParameters (FuncCall | StaticCall | MethodCall $ call ): bool
22+ public function hasVariadicParameters (FuncCall | StaticCall | MethodCall | New_ $ call ): bool
2223 {
2324 $ functionLikeReflection = $ this ->reflectionResolver ->resolveFunctionLikeReflectionFromCall ($ call );
2425 if ($ functionLikeReflection === null ) {
You can’t perform that action at this time.
0 commit comments