diff --git a/src/CG/Generator/BuiltinType.php b/src/CG/Generator/BuiltinType.php index 4317118..afcd090 100644 --- a/src/CG/Generator/BuiltinType.php +++ b/src/CG/Generator/BuiltinType.php @@ -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 diff --git a/src/CG/Proxy/InterceptionGenerator.php b/src/CG/Proxy/InterceptionGenerator.php index fd81ccf..2044c72 100644 --- a/src/CG/Proxy/InterceptionGenerator.php +++ b/src/CG/Proxy/InterceptionGenerator.php @@ -95,12 +95,16 @@ 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) { @@ -108,8 +112,11 @@ public function generate(\ReflectionClass $originalClass, PhpClass $genClass) } $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);