Skip to content

Commit 3e0bfbf

Browse files
authored
[DeadCode] Skip final and non-public __construct() on RemoveParentDelegatingConstructorRector (#7806)
* [DeadCode] Skip final and non-public __construct() on RemoveParentDelegatingConstructorRector * skip final * skip non-public * final touch: better demo fixxture
1 parent a5cdd61 commit 3e0bfbf

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 13 additions & 0 deletions
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 PhpParser\Node\Scalar\String_;
6+
7+
final class SkipFinalConstruct extends String_
8+
{
9+
final public function __construct($value, $attributes)
10+
{
11+
parent::__construct($value, $attributes);
12+
}
13+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Fixture;
4+
5+
use PhpParser\Node\Scalar\String_;
6+
7+
final class SkipPrivateConstruct extends String_
8+
{
9+
private function __construct($value, $attributes)
10+
{
11+
parent::__construct($value, $attributes);
12+
}
13+
14+
public static function create($value, $attributes)
15+
{
16+
return new self($value, $attributes);
17+
}
18+
}

rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public function refactor(Node $node): ?int
9898
return null;
9999
}
100100

101+
if ($node->isFinal()) {
102+
return null;
103+
}
104+
105+
if (! $node->isPublic()) {
106+
return null;
107+
}
108+
101109
$parentMethodReflection = $this->matchParentConstructorReflection($node);
102110
if (! $parentMethodReflection instanceof ExtendedMethodReflection) {
103111
return null;

0 commit comments

Comments
 (0)