Skip to content

Commit 64f20de

Browse files
authored
[Php84] Skip has mix between normal property and readonly promoted property on PropertyHookRector (#7504)
* [Php84] Skip has normal property, and readonly promoted property on PropertyHookRector * fix
1 parent 4945203 commit 64f20de

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php84\Rector\Class_\PropertyHookRector\Fixture;
4+
5+
final class SkipMixReadonlyPromotedProperty
6+
{
7+
private string $name;
8+
9+
public function getName(): string
10+
{
11+
return $this->name;
12+
}
13+
14+
public function setName(string $name): void
15+
{
16+
$this->name = ucfirst($name);
17+
}
18+
19+
public function __construct(
20+
private readonly int $value,
21+
)
22+
{
23+
}
24+
25+
public function getValue()
26+
{
27+
return $this->value;
28+
}
29+
}

rules/Php84/NodeFinder/SetterAndGetterFinder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\Stmt\Class_;
88
use PhpParser\Node\Stmt\ClassMethod;
99
use Rector\TypeDeclaration\NodeAnalyzer\ClassMethodAndPropertyAnalyzer;
10+
use Rector\ValueObject\MethodName;
1011

1112
final readonly class SetterAndGetterFinder
1213
{
@@ -22,6 +23,16 @@ public function findGetterAndSetterClassMethods(Class_ $class, string $propertyN
2223
{
2324
$classMethods = [];
2425

26+
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
27+
28+
if ($constructClassMethod instanceof ClassMethod) {
29+
foreach ($constructClassMethod->params as $param) {
30+
if ($param->isReadonly()) {
31+
return [];
32+
}
33+
}
34+
}
35+
2536
$getterClassMethod = $this->findGetterClassMethod($class, $propertyName);
2637
if ($getterClassMethod instanceof ClassMethod) {
2738
$classMethods[] = $getterClassMethod;

0 commit comments

Comments
 (0)