Skip to content

Commit cf82f6a

Browse files
Fix WrapReturnRector (#6798)
1 parent 498c44b commit cf82f6a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

rules/Transform/Rector/ClassMethod/WrapReturnRector.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ public function refactor(Node $node): ?Node
8686
continue;
8787
}
8888

89-
$this->wrap($classMethod, $typeMethodWrap->isArrayWrap());
90-
$hasChanged = true;
89+
if ($typeMethodWrap->isArrayWrap() && $this->wrap($classMethod)) {
90+
$hasChanged = true;
91+
}
9192
}
9293
}
9394

@@ -107,22 +108,21 @@ public function configure(array $configuration): void
107108
$this->typeMethodWraps = $configuration;
108109
}
109110

110-
private function wrap(ClassMethod $classMethod, bool $isArrayWrap): ?ClassMethod
111+
private function wrap(ClassMethod $classMethod): bool
111112
{
112113
if (! is_iterable($classMethod->stmts)) {
113-
return null;
114+
return false;
114115
}
115116

116-
foreach ($classMethod->stmts as $key => $stmt) {
117-
if ($stmt instanceof Return_ && $stmt->expr instanceof Expr) {
118-
if ($isArrayWrap && ! $stmt->expr instanceof Array_) {
119-
$stmt->expr = new Array_([new ArrayItem($stmt->expr)]);
120-
}
121-
122-
$classMethod->stmts[$key] = $stmt;
117+
$hasChanged = false;
118+
foreach ($classMethod->stmts as $stmt) {
119+
if ($stmt instanceof Return_ && $stmt->expr instanceof Expr
120+
&& ! $stmt->expr instanceof Array_) {
121+
$stmt->expr = new Array_([new ArrayItem($stmt->expr)]);
122+
$hasChanged = true;
123123
}
124124
}
125125

126-
return $classMethod;
126+
return $hasChanged;
127127
}
128128
}

0 commit comments

Comments
 (0)