Skip to content

Commit 673e3ab

Browse files
authored
[Php80] Handle with property hook on ClassPropertyAssignToConstructorPromotionRector (#7024)
1 parent 9e92922 commit 673e3ab

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;
4+
5+
final class WithPropertyHook
6+
{
7+
private string $foo {
8+
get => strtoupper($this->foo);
9+
set {
10+
$this->foo = $value;
11+
}
12+
}
13+
14+
public function __construct(
15+
string $foo,
16+
) {
17+
$this->foo = $foo;
18+
}
19+
}
20+
21+
?>
22+
-----
23+
<?php
24+
25+
namespace Rector\Tests\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector\Fixture;
26+
27+
final class WithPropertyHook
28+
{
29+
public function __construct(private string $foo {
30+
get => strtoupper($this->foo);
31+
set {
32+
$this->foo = $value;
33+
}
34+
})
35+
{
36+
}
37+
}
38+
39+
?>

rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public function refactor(Node $node): ?Node
226226
$paramName = $this->getName($property);
227227
$param->var = new Variable($paramName);
228228
$param->flags = $property->flags;
229+
$param->hooks = $property->hooks;
229230

230231
// copy attributes of the old property
231232
$param->attrGroups = array_merge($param->attrGroups, $property->attrGroups);

0 commit comments

Comments
 (0)