Skip to content

Commit b91e37a

Browse files
committed
skip nullable property without null default, as null is always passed from outside to trigger
1 parent 79a385f commit b91e37a

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

rules/Php81/Rector/ClassMethod/NewInInitializerRector.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ public function getNodeTypes(): array
8181
*/
8282
public function refactor(Node $node): ?Node
8383
{
84-
if ($node->stmts === null || $node->stmts === []) {
85-
return null;
86-
}
87-
88-
if ($node->isAbstract() || $node->isAnonymous()) {
84+
if ($this->shouldSkipClass($node)) {
8985
return null;
9086
}
9187

@@ -104,6 +100,10 @@ public function refactor(Node $node): ?Node
104100
foreach ($params as $param) {
105101
$paramName = $this->getName($param);
106102

103+
if ($param->type instanceof NullableType && $param->default === null) {
104+
continue;
105+
}
106+
107107
$coalesce = $this->coalescePropertyAssignMatcher->matchCoalesceAssignsToLocalPropertyNamed(
108108
$stmt,
109109
$paramName
@@ -215,4 +215,13 @@ private function matchConstructorParams(ClassMethod $classMethod): array
215215

216216
return $params;
217217
}
218+
219+
private function shouldSkipClass(Class_ $class): bool
220+
{
221+
if ($class->stmts === []) {
222+
return true;
223+
}
224+
225+
return $class->isAbstract() || $class->isAnonymous();
226+
}
218227
}

0 commit comments

Comments
 (0)