Completed
Push — master ( 993e47...b8c606 )
by Dawid
15:17 queued 12:48
created

LazyLoadingValueHolderFactoryFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getProxyManagerConfiguration() 0 11 2
A getFactory() 0 12 3
1
<?php
2
3
namespace Spiechu\LazyPimple\Factory;
4
5
use ProxyManager\Configuration;
6
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
7
8
class LazyLoadingValueHolderFactoryFactory
9
{
10
    /**
11
     * @param string|null $proxyManagerCacheDir
12
     *
13
     * @return LazyLoadingValueHolderFactory
14
     */
15 3
    public function getFactory($proxyManagerCacheDir = null)
16
    {
17 3
        $proxyConfiguration = is_null($proxyManagerCacheDir) ? null : $this->getProxyManagerConfiguration($proxyManagerCacheDir);
18
19 3
        $lazyLoadingFactory = new LazyLoadingValueHolderFactory($proxyConfiguration);
20
21 3
        if ($proxyConfiguration instanceof Configuration) {
22 3
            spl_autoload_register($proxyConfiguration->getProxyAutoloader(), true, true);
23
        }
24
25 3
        return $lazyLoadingFactory;
26
    }
27
28
    /**
29
     * @param string $proxyManagerCacheDir
30
     *
31
     * @return Configuration
32
     *
33
     * @throws \InvalidArgumentException When $proxyManagerCacheDir is not a dir
34
     */
35 3
    protected function getProxyManagerConfiguration($proxyManagerCacheDir)
36
    {
37 3
        if (!is_dir($proxyManagerCacheDir)) {
38
            throw new \InvalidArgumentException(sprintf('"%s" is not a dir', $proxyManagerCacheDir));
39
        }
40
41 3
        $proxyConfiguration = new Configuration();
42 3
        $proxyConfiguration->setProxiesTargetDir($proxyManagerCacheDir);
43
44 3
        return $proxyConfiguration;
45
    }
46
}
47