Skip to content

Commit c5d9fdf

Browse files
committed
skip all-typed properties in TypedPropertyFromStrictConstructorRector
1 parent 08f6dc3 commit c5d9fdf

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ public function getNodeTypes(): array
9393
public function refactor(Node $node): ?Node
9494
{
9595
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
96-
if (! $constructClassMethod instanceof ClassMethod || $node->getProperties() === []) {
96+
if (! $constructClassMethod instanceof ClassMethod) {
97+
return null;
98+
}
99+
100+
if (! $this->hasSomeUntypedProperties($node)) {
97101
return null;
98102
}
99103

@@ -180,4 +184,17 @@ private function shouldSkipPropertyType(Type $propertyType): bool
180184

181185
return $this->doctrineTypeAnalyzer->isInstanceOfCollectionType($propertyType);
182186
}
187+
188+
private function hasSomeUntypedProperties(Node|Class_ $node): bool
189+
{
190+
foreach ($node->getProperties() as $property) {
191+
if ($property->type instanceof \PhpParser\Node) {
192+
continue;
193+
}
194+
195+
return true;
196+
}
197+
198+
return false;
199+
}
183200
}

0 commit comments

Comments
 (0)