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

LazyLoadingValueHolderFactory::getGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 6
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