Completed
Pull Request — master (#279)
by Marco
28:36 queued 05:21
created

getGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 0
crap 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