Completed
Pull Request — master (#391)
by Marco
07:35
created

NullObjectFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createProxy() 0 7 2
A getGenerator() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Factory;
6
7
use ProxyManager\Proxy\NullObjectInterface;
8
use ProxyManager\ProxyGenerator\NullObjectGenerator;
9
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
10
use ProxyManager\Signature\Exception\InvalidSignatureException;
11
use ProxyManager\Signature\Exception\MissingSignatureException;
12
13
/**
14
 * Factory responsible of producing proxy objects
15
 *
16
 * @author Vincent Blanchon <[email protected]>
17
 * @license MIT
18
 */
19
class NullObjectFactory extends AbstractBaseFactory
20
{
21
    /**
22
     * @var \ProxyManager\ProxyGenerator\NullObjectGenerator|null
23
     */
24
    private $generator;
25
26
    /**
27
     * @param object|string $instanceOrClassName the object to be wrapped or interface to transform to null object
28
     *
29
     * @throws InvalidSignatureException
30
     * @throws MissingSignatureException
31
     * @throws \OutOfBoundsException
32
     */
33 2
    public function createProxy($instanceOrClassName) : NullObjectInterface
34
    {
35 2
        $className      = is_object($instanceOrClassName) ? get_class($instanceOrClassName) : $instanceOrClassName;
36 2
        $proxyClassName = $this->generateProxy($className);
37
38 2
        return $proxyClassName::staticProxyConstructor();
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 1
    protected function getGenerator() : ProxyGeneratorInterface
45
    {
46 1
        return $this->generator ?: $this->generator = new NullObjectGenerator();
47
    }
48
}
49