Completed
Pull Request — master (#393)
by
unknown
03:05
created

LazyLoadingValueHolderFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 25
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createProxy() 0 9 1
A getGenerator() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManager\Factory;
6
7
use ProxyManager\Proxy\VirtualProxyInterface;
8
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
9
use ProxyManager\ProxyGenerator\ProxyGeneratorInterface;
10
11
/**
12
 * Factory responsible of producing virtual proxy instances
13
 *
14
 * @author Marco Pivetta <[email protected]>
15
 * @license MIT
16
 */
17
class LazyLoadingValueHolderFactory extends AbstractBaseFactory
18
{
19
    /**
20
     * @var \ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator|null
21
     */
22
    private $generator;
23
24 1
    public function createProxy(
25
        string $className,
26
        \Closure $initializer,
27
        array $proxyOptions = []
28
    ) : VirtualProxyInterface {
29 1
        $proxyClassName = $this->generateProxy($className, $proxyOptions);
30
31 1
        return $proxyClassName::staticProxyConstructor($initializer);
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    protected function getGenerator() : ProxyGeneratorInterface
38
    {
39
        return $this->generator ?: $this->generator = new LazyLoadingValueHolderGenerator();
40
    }
41
}
42