Skip to content

Commit 7ce9170

Browse files
committed
skip property promotion not readonly
1 parent 22936ae commit 7ce9170

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

rules/Php82/Rector/Class_/ReadOnlyClassRector.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66

77
use PhpParser\Node;
88
use PhpParser\Node\Stmt\Class_;
9+
use PhpParser\Node\Stmt\ClassMethod;
910
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
1011
use Rector\Core\Rector\AbstractRector;
12+
use Rector\Core\ValueObject\MethodName;
1113
use Rector\Core\ValueObject\PhpVersionFeature;
1214
use Rector\Core\ValueObject\Visibility;
1315
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
@@ -100,13 +102,28 @@ private function shouldSkip(Class_ $class): bool
100102
return true;
101103
}
102104

105+
if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
106+
return true;
107+
}
108+
103109
$properties = $class->getProperties();
104110
foreach ($properties as $property) {
105111
if (! $property->isReadonly()) {
106112
return true;
107113
}
108114
}
109-
// property promotion
110-
return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE);
115+
116+
$constructClassMethod = $class->getMethod(MethodName::CONSTRUCT);
117+
if (! $constructClassMethod instanceof ClassMethod) {
118+
return false;
119+
}
120+
121+
foreach ($constructClassMethod->getParams() as $param) {
122+
if ($param->flags !== 0) {
123+
return true;
124+
}
125+
}
126+
127+
return false;
111128
}
112129
}

0 commit comments

Comments
 (0)