Completed
Push — master ( b9df3b...6e99df )
by Marco
21:56 queued 17:12
created

AccessInterceptorValueHolderFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 34
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createProxy() 0 9 1
A getGenerator() 0 4 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types=1);
20
21
namespace ProxyManager\Factory;
22
23
use ProxyManager\Proxy\AccessInterceptorValueHolderInterface;
24
use ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator;
25
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
26
27
/**
28
 * Factory responsible of producing proxy objects
29
 *
30
 * @author Marco Pivetta <[email protected]>
31
 * @license MIT
32
 */
33
class AccessInterceptorValueHolderFactory extends AbstractBaseFactory
34
{
35
    /**
36
     * @var \ProxyManager\ProxyGenerator\AccessInterceptorValueHolderGenerator|null
37
     */
38
    private $generator;
39
40
    /**
41
     * @param object     $instance           the object to be wrapped within the value holder
42
     * @param \Closure[] $prefixInterceptors an array (indexed by method name) of interceptor closures to be called
43
     *                                       before method logic is executed
44
     * @param \Closure[] $suffixInterceptors an array (indexed by method name) of interceptor closures to be called
45
     *                                       after method logic is executed
46
     *
47
     * @return AccessInterceptorValueHolderInterface
48
     */
49 2
    public function createProxy(
50
        $instance,
51
        array $prefixInterceptors = [],
52
        array $suffixInterceptors = []
53
    ) : AccessInterceptorValueHolderInterface {
1 ignored issue
show
Coding Style introduced by
There must be a single space between the closing parenthesis and the opening brace of a multi-line function declaration
Loading history...
54 2
        $proxyClassName = $this->generateProxy(get_class($instance));
55
56 2
        return $proxyClassName::staticProxyConstructor($instance, $prefixInterceptors, $suffixInterceptors);
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    protected function getGenerator() : ProxyGeneratorInterface
63
    {
64 1
        return $this->generator ?: $this->generator = new AccessInterceptorValueHolderGenerator();
65
    }
66
}
67