StaticProxyConstructor   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 42
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 34 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator;
6
7
use Laminas\Code\Generator\Exception\InvalidArgumentException;
8
use Laminas\Code\Generator\ParameterGenerator;
9
use ProxyManager\Generator\MethodGenerator;
10
use ReflectionClass;
11
12
/**
13
 * The `staticProxyConstructor` implementation for an access interceptor scope localizer proxy
14
 */
15
class StaticProxyConstructor extends MethodGenerator
16
{
17
    /**
18
     * Constructor
19
     *
20
     * @throws InvalidArgumentException
21
     */
22
    public function __construct(ReflectionClass $originalClass)
23
    {
24 2
        parent::__construct('staticProxyConstructor', [], self::FLAG_PUBLIC | self::FLAG_STATIC);
25
26 2
        $localizedObject = new ParameterGenerator('localizedObject');
27
        $prefix          = new ParameterGenerator('prefixInterceptors');
28 2
        $suffix          = new ParameterGenerator('suffixInterceptors');
29 2
30 2
        $localizedObject->setType($originalClass->getName());
31
        $prefix->setDefaultValue([]);
32 2
        $suffix->setDefaultValue([]);
33 2
        $prefix->setType('array');
34 2
        $suffix->setType('array');
35 2
36 2
        $this->setParameter($localizedObject);
37
        $this->setParameter($prefix);
38 2
        $this->setParameter($suffix);
39 2
        $this->setReturnType($originalClass->getName());
40 2
41 2
        $this->setDocBlock(
42
            "Constructor to setup interceptors\n\n"
43 2
            . '@param \\' . $originalClass->getName() . " \$localizedObject\n"
44
            . "@param \\Closure[] \$prefixInterceptors method interceptors to be used before method logic\n"
45 2
            . "@param \\Closure[] \$suffixInterceptors method interceptors to be used before method logic\n\n"
46 2
            . '@return self'
47 2
        );
48 2
        $this->setBody(
49
            'static $reflection;' . "\n\n"
50 2
            . '$reflection = $reflection ?? new \ReflectionClass(__CLASS__);' . "\n"
51
            . '$instance   = $reflection->newInstanceWithoutConstructor();' . "\n\n"
52
            . '$instance->bindProxyProperties($localizedObject, $prefixInterceptors, $suffixInterceptors);' . "\n\n"
53
            . 'return $instance;'
54
        );
55 2
    }
56
}
57