InterceptedMethod::generateMethod()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 9.504
c 0
b 0
f 0
cc 3
nc 3
nop 4
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator;
6
7
use Laminas\Code\Generator\Exception\InvalidArgumentException;
8
use Laminas\Code\Generator\PropertyGenerator;
9
use Laminas\Code\Reflection\MethodReflection;
10
use ProxyManager\Generator\MethodGenerator;
11
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolder\MethodGenerator\Util\InterceptorGenerator;
12
use function implode;
13
14
/**
15
 * Method with additional pre- and post- interceptor logic in the body
16
 */
17
class InterceptedMethod extends MethodGenerator
18
{
19
    /**
20
     * @throws InvalidArgumentException
21
     */
22
    public static function generateMethod(
23 1
        MethodReflection $originalMethod,
24
        PropertyGenerator $valueHolderProperty,
25
        PropertyGenerator $prefixInterceptors,
26
        PropertyGenerator $suffixInterceptors
27
    ) : self {
28
        /** @var self $method */
29
        $method          = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
30 1
        $forwardedParams = [];
31 1
32
        foreach ($originalMethod->getParameters() as $parameter) {
33 1
            $forwardedParams[] = ($parameter->isVariadic() ? '...' : '') . '$' . $parameter->getName();
0 ignored issues
show
Bug introduced by
The method isVariadic() does not seem to exist on object<Laminas\Code\Refl...on\ParameterReflection>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34 1
        }
35
36
        $method->setBody(InterceptorGenerator::createInterceptedMethodBody(
37 1
            '$returnValue = $this->' . $valueHolderProperty->getName() . '->'
38 1
            . $originalMethod->getName() . '(' . implode(', ', $forwardedParams) . ');',
39 1
            $method,
40 1
            $valueHolderProperty,
41 1
            $prefixInterceptors,
42 1
            $suffixInterceptors,
43 1
            $originalMethod
44 1
        ));
45
46
        return $method;
47 1
    }
48
}
49