Completed
Pull Request — master (#40)
by Marko
116:46 queued 51:48
created

PluginManager   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 69
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A hasPlugins() 0 4 1
A getPlugins() 0 4 1
A setPlugins() 0 6 2
A hasPlugin() 0 4 1
A getPlugin() 0 8 2
A setPlugin() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\CKEditorBundle\Model;
13
14
use FOS\CKEditorBundle\Exception\PluginManagerException;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class PluginManager implements PluginManagerInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $plugins = [];
25
26
    /**
27
     * @param array $plugins
28
     */
29
    public function __construct(array $plugins = [])
30
    {
31
        $this->setPlugins($plugins);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function hasPlugins()
38
    {
39
        return !empty($this->plugins);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getPlugins()
46
    {
47
        return $this->plugins;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function setPlugins(array $plugins)
54
    {
55
        foreach ($plugins as $name => $plugin) {
56
            $this->setPlugin($name, $plugin);
57
        }
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function hasPlugin($name)
64
    {
65
        return isset($this->plugins[$name]);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getPlugin($name)
72
    {
73
        if (!$this->hasPlugin($name)) {
74
            throw PluginManagerException::pluginDoesNotExist($name);
75
        }
76
77
        return $this->plugins[$name];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function setPlugin($name, array $plugin)
84
    {
85
        $this->plugins[$name] = $plugin;
86
    }
87
}
88