Completed
Pull Request — master (#540)
by
unknown
21:29
created

RemoteObjectMethod   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator;
6
7
use ProxyManager\Generator\MethodGenerator;
8
use ProxyManager\Generator\Util\ProxiedMethodReturnExpression;
9
use ReflectionClass;
10
use Zend\Code\Generator\PropertyGenerator;
11
use Zend\Code\Reflection\MethodReflection;
12
13
use function str_replace;
14
use function var_export;
15
16
/**
17
 * Method decorator for remote objects
18
 */
19
class RemoteObjectMethod extends MethodGenerator
20 3
{
21
    /** @var string */
22
    private const TEMPLATE
23
        = <<<PHP
24
\$reflectionMethod = new \\ReflectionMethod(__CLASS__, __FUNCTION__);
25
\$args = \\func_get_args();
26 3
foreach (\\array_slice(\$reflectionMethod->getParameters(), \\count(\$args)) as \$param) {
27
            /**
28 3
             * @var ReflectionParameter \$param
29 3
             */
30 3
            if (\$param->isDefaultValueAvailable()) {
31 3
                \$args[] = \$param->getDefaultValue();
32 3
            }
33
}
34
35 3
#proxiedReturn#
36
PHP;
37
38
    /** @return self|static */
39
    public static function generateMethod(
40
        MethodReflection $originalMethod,
41
        PropertyGenerator $adapterProperty,
42
        ReflectionClass $originalClass
43
    ): self {
44
        /** @var self $method */
45
        $method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
46
        $proxiedReturn = '$return = $this->' . $adapterProperty->getName()
47
            . '->call(' . var_export($originalClass->getName(), true)
48
            . ', ' . var_export($originalMethod->getName(), true) . ', $args);' . "\n\n"
49
            . ProxiedMethodReturnExpression::generate('$return', $originalMethod);
50
51
        $body = str_replace(
52
            ['#proxiedReturn#'],
53
            ['#proxciedReturn#' => $proxiedReturn],
54
            self::TEMPLATE,
55
        );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ')'
Loading history...
56
57
        $method->setBody(
58
            $body
59
        );
60
61
        return $method;
62
    }
63
}
64