Skip to content

Commit 34b45d4

Browse files
authored
[Php80] Skip not match property hook type with parameter type on ClassPropertyAssignToConstructorPromotionRector (#7109)
* [Php80] Skip not match property hook type with parameter type on ClassPropertyAssignToConstructorPromotionRector * eol * fix per use case
1 parent 8b62770 commit 34b45d4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;
4+
5+
class SkipNotMatchPropertyHookType {
6+
protected \stdClass $origin {
7+
set(array|\stdClass $origin) {
8+
$this->origin = is_array($origin) ? (object) $origin : clone $origin;
9+
}
10+
}
11+
12+
public function __construct(
13+
array|\stdClass $origin
14+
) {
15+
$this->origin = $origin;
16+
}
17+
}

rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ public function refactor(Node $node): ?Node
206206
continue;
207207
}
208208

209+
if ($property->type instanceof Node
210+
&& $param->type instanceof Node
211+
&& $property->hooks !== []
212+
&& ! $this->nodeComparator->areNodesEqual($property->type, $param->type)) {
213+
continue;
214+
}
215+
209216
$hasChanged = true;
210217

211218
// remove property from class

0 commit comments

Comments
 (0)