PluginManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 74
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 7 2
A install() 0 4 1
A remove() 0 4 1
A registerAssetBundles() 0 6 2
A getInstalledPlugins() 0 4 1
A getPlugin() 0 4 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC
4
 * @link http://2amigos.us
5
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
6
 */
7
namespace dosamigos\leaflet;
8
9
use yii\base\Component;
10
use yii\helpers\ArrayHelper;
11
12
class PluginManager extends Component
13
{
14
    private $_plugins = [];
15
16
    /**
17
     * Check whether we have a plugin installed with that name previous firing up the call
18
     *
19
     * @param string $name
20
     *
21
     * @return mixed|void
22
     */
23 3
    public function __get($name)
24
    {
25 3
        if (ArrayHelper::keyExists($name, $this->getInstalledPlugins())) {
26 3
            return $this->getPlugin($name);
27
        }
28 3
        return parent::__get($name);
29
    }
30
31
    /**
32
     * Installs a plugin
33
     *
34
     * @param Plugin $plugin
35
     *
36
     * @return void
37
     */
38 18
    public function install(Plugin $plugin)
39
    {
40 18
        $this->_plugins[$plugin->name] = $plugin;
41 18
    }
42
43
    /**
44
     * Removes a plugin
45
     *
46
     * @param Plugin $plugin
47
     *
48
     * @return mixed|null the value of the element if found, default value otherwise
49
     */
50 3
    public function remove(Plugin $plugin)
51
    {
52 3
        return ArrayHelper::remove($this->_plugins, $plugin->name);
53
    }
54
55
    /**
56
     * @param \yii\web\View $view
57
     * Registers plugin bundles
58
     */
59 15
    public function registerAssetBundles($view)
60
    {
61 15
        foreach ($this->_plugins as $plugin) {
62 12
            $plugin->registerAssetBundle($view);
63 15
        }
64 15
    }
65
66
    /**
67
     * @return array of installed plugins
68
     */
69 21
    public function getInstalledPlugins()
70
    {
71 21
        return $this->_plugins;
72
    }
73
74
    /**
75
     * Returns an installed plugin by name
76
     *
77
     * @param string $name
78
     *
79
     * @return Plugin|null
80
     */
81 3
    public function getPlugin($name)
82
    {
83 3
        return isset($this->_plugins[$name]) ? $this->_plugins[$name] : null;
84
    }
85
}
86