Passed
Push — master ( 111a28...a72b65 )
by Phillip
01:16
created

PluginLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Deployee\Components\Plugins;
5
6
7
use Deployee\Components\Container\ContainerInterface;
8
use Deployee\Components\Plugins\Locator\PluginLocator;
9
10
class PluginLoader
11
{
12
    /**
13
     * @var ContainerInterface
14
     */
15
    private $container;
16
17
    /**
18
     * @var PluginLocator
19
     */
20
    private $locator;
21
22
    /**
23
     * @param ContainerInterface $container
24
     */
25 1
    public function __construct(ContainerInterface $container)
26
    {
27 1
        $this->container = $container;
28 1
        $this->locator = new PluginLocator();
29 1
    }
30
31
    /**
32
     * @return array
33
     */
34 1
    public function loadPlugins(): array
35
    {
36 1
        $list = [];
37 1
        foreach($this->locator->locatePlugins() as $pluginClass){
38 1
            $list[$pluginClass] = new $pluginClass();
39
        }
40
41 1
        $container = $this->container;
42 1
        array_walk($list, function(PluginInterface $plugin) use ($container){
43 1
            $plugin->boot($container);
44 1
        });
45
46 1
        return $list;
47
    }
48
}