PluginLoader::loadPlugins()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

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