AbstractPluginManagerFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 0
cbo 1
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 10 4
getConfigKey() 0 1 ?
getClassName() 0 1 ?
1
<?php
2
/**
3
 * Dash
4
 *
5
 * @link      http://github.com/DASPRiD/Dash For the canonical source repository
6
 * @copyright 2013-2015 Ben Scholzen 'DASPRiD'
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Dash;
11
12
use Interop\Container\ContainerInterface;
13
use Zend\ServiceManager\AbstractPluginManager;
14
15
/**
16
 * Abstract factory for plugin managers.
17
 */
18
abstract class AbstractPluginManagerFactory
19
{
20
    /**
21
     * @var string
22
     */
23
    private $configKey;
24
25
    /**
26
     * @var string
27
     */
28
    private $className;
29
30
    /**
31
     * Caches the abstract getter results to eliminate performance impact.
32
     */
33
    public function __construct()
34
    {
35
        $this->configKey = $this->getConfigKey();
36
        $this->className = $this->getClassName();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @return AbstractPluginManager
43
     */
44
    public function __invoke(ContainerInterface $container)
45
    {
46
        $config = $container->has('config') ? $container->get('config') : [];
47
48
        if (isset($config['dash'][$this->configKey]) && is_array($config['dash'][$this->configKey])) {
49
            return new $this->className($container, $config['dash'][$this->configKey]);
50
        }
51
52
        return new $this->className($container);
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    abstract protected function getConfigKey();
59
60
    /**
61
     * @return string
62
     */
63
    abstract protected function getClassName();
64
}
65