Skip to content

Commit

Permalink
Add support for void return types for PHP7.1, see #307
Browse files Browse the repository at this point in the history
  • Loading branch information
lisachenko committed Jan 5, 2017
1 parent c79ecee commit 21b7a2d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/Proxy/ClassProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,21 @@ protected function getJoinpointInvocationBody(ReflectionMethod $method)
$scope = $isStatic ? self::$staticLsbExpression : '$this';
$prefix = $isStatic ? AspectContainer::STATIC_METHOD_PREFIX : AspectContainer::METHOD_PREFIX;

$args = $this->prepareArgsLine($method);
$body = '';
$args = $this->prepareArgsLine($method);
$return = 'return ';
if (PHP_VERSION_ID >= 70100 && $method->hasReturnType()) {
$returnType = (string) $method->getReturnType();
if ($returnType === 'void') {
// void return types should not return anything
$return = '';
}
}

if (!empty($args)) {
$scope = "$scope, $args";
}

$body .= "return self::\$__joinPoints['{$prefix}:{$method->name}']->__invoke($scope);";
$body = "{$return}self::\$__joinPoints['{$prefix}:{$method->name}']->__invoke($scope);";

return $body;
}
Expand Down
11 changes: 10 additions & 1 deletion src/Proxy/FunctionProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,21 @@ protected function getJoinpointInvocationBody(ReflectionFunction $function)

$args = $this->prepareArgsLine($function);

$return = 'return ';
if (PHP_VERSION_ID >= 70100 && $function->hasReturnType()) {
$returnType = (string) $function->getReturnType();
if ($returnType === 'void') {
// void return types should not return anything
$return = '';
}
}

return <<<BODY
static \$__joinPoint = null;
if (!\$__joinPoint) {
\$__joinPoint = {$class}::getJoinPoint('{$function->name}', __NAMESPACE__);
}
return \$__joinPoint->__invoke($args);
{$return}\$__joinPoint->__invoke($args);
BODY;
}

Expand Down
11 changes: 10 additions & 1 deletion src/Proxy/TraitProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,21 @@ protected function getJoinpointInvocationBody(ReflectionMethod $method)
$args = $this->prepareArgsLine($method);
$args = $scope . ($args ? ", $args" : '');

$return = 'return ';
if (PHP_VERSION_ID >= 70100 && $method->hasReturnType()) {
$returnType = (string) $method->getReturnType();
if ($returnType === 'void') {
// void return types should not return anything
$return = '';
}
}

return <<<BODY
static \$__joinPoint = null;
if (!\$__joinPoint) {
\$__joinPoint = {$class}::getJoinPoint(__TRAIT__, __CLASS__, '{$prefix}', '{$method->name}');
}
return \$__joinPoint->__invoke($args);
{$return}\$__joinPoint->__invoke($args);
BODY;
}

Expand Down

0 comments on commit 21b7a2d

Please sign in to comment.