Skip to content

Commit

Permalink
schmittjoh#35 fix codegen for return void
Browse files Browse the repository at this point in the history
  • Loading branch information
4n70w4 committed Feb 14, 2019
1 parent 2152ea2 commit 7bcc767
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/CG/Generator/BuiltinType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class BuiltinType
{
private static $builtinTypes = array('self', 'array', 'callable', 'bool', 'float', 'int', 'string');
private static $builtinTypes = array('self', 'array', 'callable', 'bool', 'float', 'int', 'string', 'void');

private function __construct(){
// Static class
Expand Down
15 changes: 11 additions & 4 deletions src/CG/Proxy/InterceptionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,28 @@ public function generate(\ReflectionClass $originalClass, PhpClass $genClass)
$loaderSetter->addParameter($loaderParam);

$interceptorCode =
'$ref = new \ReflectionMethod(%s, %s);'."\n"
'$ref = new \ReflectionMethod(%s, %s);'."\n"
.'$interceptors = $this->'.$this->prefix.'loader->loadInterceptors($ref, $this, array(%s));'."\n"
.'$invocation = new \CG\Proxy\MethodInvocation($ref, $this, array(%s), $interceptors);'."\n\n"
.'return $invocation->proceed();'
;

$voidReturns = array(
true => '$invocation->proceed();',
false => 'return $invocation->proceed();'
);

foreach ($methods as $method) {
$params = array();
foreach ($method->getParameters() as $param) {
$params[] = '$'.$param->name;
}
$params = implode(', ', $params);

$genMethod = PhpMethod::fromReflection($method)
->setBody(sprintf($interceptorCode, var_export(ClassUtils::getUserClass($method->class), true), var_export($method->name, true), $params, $params))
$genMethod = PhpMethod::fromReflection($method);

$isVoid = 'void' === $genMethod->getReturnType();

$genMethod->setBody(sprintf($interceptorCode . $voidReturns[$isVoid], var_export(ClassUtils::getUserClass($method->class), true), var_export($method->name, true), $params, $params))
->setDocblock(null)
;
$genClass->setMethod($genMethod);
Expand Down

0 comments on commit 7bcc767

Please sign in to comment.