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

RemoteObjectFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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\Configuration;
24
use ProxyManager\Factory\RemoteObject\AdapterInterface;
25
use ProxyManager\Proxy\RemoteObjectInterface;
26
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
27
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
28
29
/**
30
 * Factory responsible of producing remote proxy objects
31
 *
32
 * @author Vincent Blanchon <[email protected]>
33
 * @license MIT
34
 */
35
class RemoteObjectFactory extends AbstractBaseFactory
36
{
37
    /**
38
     * @var AdapterInterface
39
     */
40
    protected $adapter;
41
42
    /**
43
     * @var \ProxyManager\ProxyGenerator\RemoteObjectGenerator|null
44
     */
45
    private $generator;
46
47
    /**
48
     * {@inheritDoc}
49
     *
50
     * @param AdapterInterface $adapter
51
     * @param Configuration    $configuration
52
     */
53 2
    public function __construct(AdapterInterface $adapter, Configuration $configuration = null)
54
    {
55 2
        parent::__construct($configuration);
56
57 2
        $this->adapter = $adapter;
58 2
    }
59
60
    /**
61
     * @param string|object $instanceOrClassName
62
     *
63
     * @return RemoteObjectInterface
64
     */
65 2
    public function createProxy($instanceOrClassName) : RemoteObjectInterface
66
    {
67 2
        $proxyClassName = $this->generateProxy(
68 2
            is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName
69
        );
70
71 2
        return $proxyClassName::staticProxyConstructor($this->adapter);
72
    }
73
74
    /**
75
     * {@inheritDoc}
76
     */
77 1
    protected function getGenerator() : ProxyGeneratorInterface
78
    {
79 1
        return $this->generator ?: $this->generator = new RemoteObjectGenerator();
80
    }
81
}
82