Completed
Push — master ( f1eedc...1b618f )
by Adam
05:55
created

BundleLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A registerBundles() 0 12 3
A getLocator() 0 4 1
1
<?php
2
3
namespace WellCommerce\Bundle\CoreBundle\Loader;
4
5
use Doctrine\Common\Collections\Collection;
6
use Symfony\Component\HttpKernel\KernelInterface;
7
use WellCommerce\Bundle\CoreBundle\Locator\BundleLocator;
8
9
/**
10
 * Class BundleLoader
11
 *
12
 * @author  Adam Piotrowski <[email protected]>
13
 */
14
final class BundleLoader
15
{
16
    /**
17
     * @var KernelInterface
18
     */
19
    protected $kernel;
20
    
21
    public function __construct(KernelInterface $kernel)
22
    {
23
        $this->kernel = $kernel;
24
    }
25
    
26
    public function registerBundles(Collection $collection, string $environment)
27
    {
28
        if (is_file($cache = $this->kernel->getCacheDir() . '/bundles.php')) {
29
            $bundleClasses = require $cache;
30
        } else {
31
            $bundleClasses = $this->getLocator()->getBundleClasses();
32
        }
33
        
34
        foreach ($bundleClasses as $bundleClass) {
35
            $collection->add(new $bundleClass);
36
        }
37
    }
38
    
39
    private function getLocator(): BundleLocator
40
    {
41
        return new BundleLocator($this->kernel);
42
    }
43
}
44