Completed
Pull Request — master (#393)
by
unknown
03:05
created

AccessInterceptorValueHolderFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 36
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createProxy() 0 9 1
A getGenerator() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Factory;
6
7
use ProxyManager\Proxy\AccessInterceptorValueHolderInterface;
8
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
9
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
10
use ProxyManager\Signature\Exception\InvalidSignatureException;
11
use ProxyManager\Signature\Exception\MissingSignatureException;
12
13
/**
14
 * Factory responsible of producing proxy objects
15
 *
16
 * @author Marco Pivetta <[email protected]>
17
 * @license MIT
18
 */
19
class AccessInterceptorValueHolderFactory extends AbstractBaseFactory
20
{
21
    /**
22
     * @var \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator|null
23
     */
24
    private $generator;
25
26
    /**
27
     * @param object     $instance           the object to be wrapped within the value holder
28
     * @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called
29
     *                                       before method logic is executed
30
     * @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called
31
     *                                       after method logic is executed
32
     *
33
     * @throws InvalidSignatureException
34
     * @throws MissingSignatureException
35
     * @throws \OutOfBoundsException
36
     */
37 1
    public function createProxy(
38
        $instance,
39
        array $prefixInterceptors = [],
40
        array $suffixInterceptors = []
41
    ) : AccessInterceptorValueHolderInterface {
42 1
        $proxyClassName = $this->generateProxy(get_class($instance));
43
44 1
        return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    protected function getGenerator() : ProxyGeneratorInterface
51
    {
52
        return $this->generator ?: $this->generator = new AccessInterceptorValueHolderGenerator();
53
    }
54
}
55