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

NullObjectFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 28
ccs 6
cts 6
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\Proxy\NullObjectInterface;
10
use ProxyManager\ProxyGenerator\NullObjectGenerator;
11
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
12
use ProxyManager\Signature\Exception\InvalidSignatureException;
13
use ProxyManager\Signature\Exception\MissingSignatureException;
14
use function get_class;
15
use function is_object;
16
17
/**
18
 * Factory responsible of producing proxy objects
19
 */
20
class NullObjectFactory extends AbstractBaseFactory
21
{
22
    private NullObjectGenerator $generator;
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...
23
24
    public function __construct(?Configuration $configuration = null)
25
    {
26
        parent::__construct($configuration);
27
28
        $this->generator = new NullObjectGenerator();
29
    }
30
31 2
    /**
32
     * @param object|string $instanceOrClassName the object to be wrapped or interface to transform to null object
33 2
     *
34 2
     * @throws InvalidSignatureException
35
     * @throws MissingSignatureException
36 2
     * @throws OutOfBoundsException
37
     */
38
    public function createProxy($instanceOrClassName) : NullObjectInterface
39
    {
40
        $className      = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName;
41
        $proxyClassName = $this->generateProxy($className);
42 1
43
        return $proxyClassName::staticProxyConstructor();
44 1
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    protected function getGenerator() : ProxyGeneratorInterface
50
    {
51
        return $this->generator;
52
    }
53
}
54