Completed
Pull Request — master (#453)
by Marco
220:48 queued 199:45
created

AccessInterceptorScopeLocalizerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Factory;
6
7
use Closure;
8
use OutOfBoundsException;
9
use ProxyManager\Configuration;
10
use ProxyManager\Proxy\AccessInterceptorInterface;
11
use ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizerGenerator;
12
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
13
use ProxyManager\Signature\Exception\InvalidSignatureException;
14
use ProxyManager\Signature\Exception\MissingSignatureException;
15
use function get_class;
16
17
/**
18
 * Factory responsible of producing proxy objects
19
 */
20
class AccessInterceptorScopeLocalizerFactory extends AbstractBaseFactory
21
{
22
    private AccessInterceptorScopeLocalizerGenerator $generator;
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 T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
23
24
    public function __construct(?Configuration $configuration = null)
25
    {
26
        parent::__construct($configuration);
27
28
        $this->generator = new AccessInterceptorScopeLocalizerGenerator();
29
    }
30
31
    /**
32
     * @param object    $instance           the object to be localized within the access interceptor
33
     * @param Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called
34 2
     *                                       before method logic is executed
35
     * @param Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called
36
     *                                       after method logic is executed
37
     *
38
     * @throws InvalidSignatureException
39 2
     * @throws MissingSignatureException
40
     * @throws OutOfBoundsException
41 2
     */
42
    public function createProxy(
43
        object $instance,
44
        array $prefixInterceptors = [],
45
        array $suffixInterceptors = []
46
    ) : AccessInterceptorInterface {
47 1
        $proxyClassName = $this->generateProxy(get_class($instance));
48
49 1
        return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors);
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    protected function getGenerator() : ProxyGeneratorInterface
56
    {
57
        return $this->generator;
58
    }
59
}
60