Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 9680718

Browse files
committed
Don't return for void return types
1 parent 6912658 commit 9680718

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/Composer/InterfaceProxier.php

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,28 +163,42 @@ private function populateMethod(Node\Stmt\ClassMethod $method): Node\Stmt\ClassM
163163
$this->uses[(string) $param->type] = $namespacedClassType;
164164
}
165165

166+
$methodBody = new Node\Expr\MethodCall(
167+
new Node\Expr\Variable('this'),
168+
'proxyCallToMainThread',
169+
[
170+
new Node\Arg(
171+
new Node\Expr\ConstFetch(
172+
new Node\Name('__FUNCTION__'),
173+
),
174+
),
175+
new Node\Arg(
176+
new Node\Expr\FuncCall(
177+
new Node\Name('\func_get_args'),
178+
),
179+
),
180+
]
181+
);
182+
166183
$method->stmts = [
167-
new Node\Stmt\Return_(
168-
new Node\Expr\MethodCall(
169-
new Node\Expr\Variable('this'),
170-
'proxyCallToMainThread',
171-
[
172-
new Node\Arg(
173-
new Node\Expr\ConstFetch(
174-
new Node\Name('__FUNCTION__'),
175-
),
176-
),
177-
new Node\Arg(
178-
new Node\Expr\FuncCall(
179-
new Node\Name('\func_get_args'),
180-
),
181-
),
182-
]
183-
)
184-
),
184+
$this->wrapMethodBody($method, $methodBody),
185185
];
186+
186187
$method->setDocComment(new Doc(''));
187188

188189
return $method;
189190
}
191+
192+
private function wrapMethodBody(Node\Stmt\ClassMethod $method, Node\Expr\MethodCall $methodBody): Node\Stmt
193+
{
194+
/**
195+
* @psalm-suppress PossiblyInvalidCast
196+
* @phpstan-ignore-next-line
197+
*/
198+
if ((string) $method->getReturnType() !== 'void') {
199+
return new Node\Stmt\Return_($methodBody);
200+
}
201+
202+
return new Node\Stmt\Expression($methodBody);
203+
}
190204
}

0 commit comments

Comments
 (0)