PluginLoader::__construct()   A
last analyzed

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