Skip to content

Commit fa54d46

Browse files
authored
[DeadCode] skip Ds\Map::get() on RemoveNullArgOnNullDefaultParamRector (#7665)
1 parent 16fc0c5 commit fa54d46

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector\Fixture;
6+
7+
use Ds\Map;
8+
9+
class SkipDsMapGet
10+
{
11+
public function foo(): void {
12+
$map = new Map();
13+
$value = $map->get('foo', null);
14+
if ($value) {
15+
//...
16+
}
17+
}
18+
}

rules/DeadCode/NodeAnalyzer/CallLikeParamDefaultResolver.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ public function resolveNullPositions(MethodCall|StaticCall|New_|FuncCall $callLi
3131
return [];
3232
}
3333

34+
if ($reflection instanceof MethodReflection && $reflection->getName() === 'get') {
35+
$classReflection = $reflection->getDeclaringClass();
36+
if ($classReflection->getName() === 'Ds\Map') {
37+
return [];
38+
}
39+
}
40+
3441
$nullPositions = [];
3542

3643
$extendedParametersAcceptor = ParametersAcceptorSelector::combineAcceptors($reflection->getVariants());

0 commit comments

Comments
 (0)