PluginLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 2
b 0
f 0
dl 0
loc 41
rs 10
ccs 16
cts 16
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadPlugins() 0 17 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
}