Skip to content

Commit a6f0ce5

Browse files
authored
[DeadCode] Handle crash when parent does not has default param and child has (#7782)
* [DeadCode] Handle crash when parent does not has default param and child has * fix * comment
1 parent afd6b04 commit a6f0ce5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture;
4+
5+
use Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Source\SomeParentWithoutDefaultParam;
6+
7+
final class SkipParentDoesNotHasDefaultParam extends SomeParentWithoutDefaultParam
8+
{
9+
public function __construct(array $value = [])
10+
{
11+
parent::__construct($value);
12+
}
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Source;
6+
7+
class SomeParentWithoutDefaultParam
8+
{
9+
public function __construct(array $value)
10+
{
11+
}
12+
}

rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ private function isDifferentDefaultValue(
265265
return false;
266266
}
267267

268+
// when child has default value, but parent does not have default value,
269+
// mark as different
270+
if (! $nativeParentParameterReflection->isDefaultValueAvailable()) {
271+
return true;
272+
}
273+
268274
$parentDefault = $nativeParentParameterReflection->getDefaultValue();
269275
if (! $this->valueResolver->isValue($defaultExpr, $parentDefault)) {
270276
return true;

0 commit comments

Comments
 (0)