Skip to content

Commit 797f02c

Browse files
authored
[DeadCode] Skip private promoted property on RemoveParentDelegatingConstructorRector (#7817)
1 parent f6d8a9e commit 797f02c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
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 Rector\Tests\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector\Source\SomeParentWithPrivatePropertyPromotion;
6+
7+
class SkipPrivatePropertyPromotion extends SomeParentWithPrivatePropertyPromotion
8+
{
9+
public function __construct(private \DateTime $d)
10+
{
11+
parent::__construct($d);
12+
}
13+
14+
public function run()
15+
{
16+
return $this->d->format('Y-m-d');
17+
}
18+
}
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 SomeParentWithPrivatePropertyPromotion
8+
{
9+
public function __construct(private \DateTime $d)
10+
{
11+
}
12+
}

rules/DeadCode/Rector/ClassMethod/RemoveParentDelegatingConstructorRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ private function areConstructorAndParentParameterTypesMatching(
220220
ExtendedMethodReflection $extendedMethodReflection
221221
): bool {
222222
foreach ($classMethod->getParams() as $position => $param) {
223+
if ($param->isPromoted() && $param->isPrivate()) {
224+
return false;
225+
}
226+
223227
$parameterType = $param->type;
224228

225229
// no type override

0 commit comments

Comments
 (0)