diff --git a/src/AspectMock/Intercept/BeforeMockTransformer.php b/src/AspectMock/Intercept/BeforeMockTransformer.php index 48dfac0..c2b7051 100644 --- a/src/AspectMock/Intercept/BeforeMockTransformer.php +++ b/src/AspectMock/Intercept/BeforeMockTransformer.php @@ -58,10 +58,13 @@ public function transform(StreamMetaData $metadata): TransformerResultEnum if ($method->isGenerator()) { $beforeDefinition = str_replace('return', 'yield', $beforeDefinition); } - if (method_exists($method, 'getReturnType') && $method->getReturnType() == 'void') { - //TODO remove method_exists($method, 'getReturnType') when support for php5 is dropped + if ($method->getReturnType() == 'void') { $beforeDefinition = str_replace('return $__am_res;', 'return;', $beforeDefinition); } + if ($method->getReturnType() == 'never') { + // Replace return with a NOOP since the method cannot return + $beforeDefinition = str_replace(' return $__am_res;', ';', $beforeDefinition); + } $reflectedParams = $method->getParameters();