Skip to content

Commit fb1ee2b

Browse files
committed
Updated Rector to commit 234de212fc22f05fb5e8914e28d4fea8bd7c3d9f
rectorphp/rector-src@234de21 [DeadCode] Skip with different default param value child vs parent on RemoveParentDelegatingConstructorRector (#7776)
1 parent d0924ce commit fb1ee2b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55

66
use PhpParser\Node;
77
use PhpParser\Node\Arg;
8+
use PhpParser\Node\Expr;
89
use PhpParser\Node\Expr\StaticCall;
910
use PhpParser\Node\Expr\Variable;
1011
use PhpParser\Node\Stmt;
1112
use PhpParser\Node\Stmt\ClassMethod;
1213
use PhpParser\Node\Stmt\Expression;
1314
use PhpParser\NodeVisitor;
15+
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionParameter;
1416
use PHPStan\Reflection\ClassReflection;
1517
use PHPStan\Reflection\ExtendedMethodReflection;
1618
use Rector\Enum\ObjectReference;
19+
use Rector\PhpParser\Node\Value\ValueResolver;
1720
use Rector\PHPStan\ScopeFetcher;
1821
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
1922
use Rector\Rector\AbstractRector;
@@ -30,9 +33,14 @@ final class RemoveParentDelegatingConstructorRector extends AbstractRector
3033
* @readonly
3134
*/
3235
private StaticTypeMapper $staticTypeMapper;
33-
public function __construct(StaticTypeMapper $staticTypeMapper)
36+
/**
37+
* @readonly
38+
*/
39+
private ValueResolver $valueResolver;
40+
public function __construct(StaticTypeMapper $staticTypeMapper, ValueResolver $valueResolver)
3441
{
3542
$this->staticTypeMapper = $staticTypeMapper;
43+
$this->valueResolver = $valueResolver;
3644
}
3745
public function getRuleDefinition(): RuleDefinition
3846
{
@@ -187,8 +195,31 @@ private function areConstructorAndParentParameterTypesMatching(ClassMethod $clas
187195
if (!$this->nodeComparator->areNodesEqual($parameterType, $parentParameterType)) {
188196
return \false;
189197
}
198+
if (!$param->default instanceof Expr) {
199+
continue;
200+
}
201+
if ($this->isDifferentDefaultValue($param->default, $extendedMethodReflection, $index)) {
202+
return \false;
203+
}
190204
}
191205
}
192206
return \true;
193207
}
208+
private function isDifferentDefaultValue(Expr $defaultExpr, ExtendedMethodReflection $extendedMethodReflection, int $index): bool
209+
{
210+
$methodName = $extendedMethodReflection->getName();
211+
// native reflection is needed to get exact default value
212+
if ($extendedMethodReflection->getDeclaringClass()->getNativeReflection()->hasMethod($methodName)) {
213+
$parentMethod = $extendedMethodReflection->getDeclaringClass()->getNativeReflection()->getMethod($methodName);
214+
$nativeParentParameterReflection = $parentMethod->getParameters()[$index] ?? null;
215+
if (!$nativeParentParameterReflection instanceof ReflectionParameter) {
216+
return \false;
217+
}
218+
$parentDefault = $nativeParentParameterReflection->getDefaultValue();
219+
if (!$this->valueResolver->isValue($defaultExpr, $parentDefault)) {
220+
return \true;
221+
}
222+
}
223+
return \false;
224+
}
194225
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '40d87af2a23d28b6da5392852afc624ec2390550';
22+
public const PACKAGE_VERSION = '234de212fc22f05fb5e8914e28d4fea8bd7c3d9f';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-24 10:28:06';
27+
public const RELEASE_DATE = '2025-12-25 13:11:38';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)