Completed
Push — master ( 3be072...ba2d3a )
by Marco
231:32 queued 209:55
created

RemoteObjectFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 2
dl 0
loc 45
ccs 10
cts 10
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 OutOfBoundsException;
8
use ProxyManager\Configuration;
9
use ProxyManager\Factory\RemoteObject\AdapterInterface;
10
use ProxyManager\Proxy\RemoteObjectInterface;
11
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
12
use ProxyManager\ProxyGenerator\RemoteObjectGenerator;
13
use ProxyManager\Signature\Exception\InvalidSignatureException;
14
use ProxyManager\Signature\Exception\MissingSignatureException;
15
use function get_class;
16
use function is_object;
17
18
/**
19
 * Factory responsible of producing remote proxy objects
20
 */
21
class RemoteObjectFactory extends AbstractBaseFactory
22
{
23
    protected AdapterInterface $adapter;
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...
24
    private RemoteObjectGenerator $generator;
25
26
    /**
27
     * {@inheritDoc}
28
     *
29
     * @param AdapterInterface $adapter
30
     * @param Configuration    $configuration
31
     */
32
    public function __construct(AdapterInterface $adapter, ?Configuration $configuration = null)
33
    {
34
        parent::__construct($configuration);
35 2
36
        $this->adapter   = $adapter;
37 2
        $this->generator = new RemoteObjectGenerator();
38
    }
39 2
40 2
    /**
41
     * @param string|object $instanceOrClassName
42
     *
43
     * @throws InvalidSignatureException
44
     * @throws MissingSignatureException
45
     * @throws OutOfBoundsException
46
     */
47
    public function createProxy($instanceOrClassName) : RemoteObjectInterface
48
    {
49 2
        $proxyClassName = $this->generateProxy(
50
            is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName
51 2
        );
52 2
53
        return $proxyClassName::staticProxyConstructor($this->adapter);
54
    }
55 2
56
    /**
57
     * {@inheritDoc}
58
     */
59
    protected function getGenerator() : ProxyGeneratorInterface
60
    {
61 1
        return $this->generator ?: $this->generator = new RemoteObjectGenerator();
62
    }
63
}
64