Completed
Push — master ( f51f05...f3abab )
by Ilias
04:15
created

Container   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 81.36%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 21
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 118
ccs 48
cts 59
cp 0.8136
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetSet() 0 4 1
A offsetGet() 0 6 1
A offsetExists() 0 6 1
A offsetUnset() 0 4 1
A factory() 0 4 1
A protect() 0 4 1
A raw() 0 6 1
A extend() 0 8 1
A keys() 0 4 1
A register() 0 4 1
B registerServiceProviderProvider() 0 18 5
A loadNamespace() 0 13 3
A ensureNamespacesLoaded() 0 8 2
1
<?php
2
3
4
namespace Dimple;
5
6
7
use Pimple\ServiceProviderInterface;
8
9
class Container extends \Pimple\Container
10
{
11
    /** @var \Pimple\Container */
12
    protected $pimpleContainer;
13
14
    /** @var string[] */
15
    protected $loadedNamespaces = array();
16
17
    /** @var ServiceProviderInterface[] */
18
    protected $namespaceProviders = array();
19
20 11
    public function __construct(array $values = array())
21
    {
22 11
        $this->pimpleContainer = new \Pimple\Container($values);
23 11
    }
24
25 6
    public function offsetSet($id, $value)
26
    {
27 6
        $this->pimpleContainer->offsetSet($id, $value);
28 6
    }
29
30 5
    public function offsetGet($id)
31
    {
32 5
        return $this->pimpleContainer->offsetGet(
33 5
            $this->ensureNamespacesLoaded($id)
34 4
        );
35
    }
36
37 1
    public function offsetExists($id)
38
    {
39 1
        return $this->pimpleContainer->offsetExists(
40 1
            $this->ensureNamespacesLoaded($id)
41 1
        );
42
    }
43
44
    public function offsetUnset($id)
45
    {
46
        $this->pimpleContainer->offsetUnset($id);
47
    }
48
49
    public function factory($callable)
50
    {
51
        return $this->pimpleContainer->factory($callable);
52
    }
53
54
    public function protect($callable)
55
    {
56
        return $this->pimpleContainer->protect($callable);
57
    }
58
59 1
    public function raw($id)
60
    {
61 1
        return $this->pimpleContainer->raw(
62 1
            $this->ensureNamespacesLoaded($id)
63 1
        );
64
    }
65
66 1
    public function extend($id, $callable)
67
    {
68 1
        $this->ensureNamespacesLoaded($id);
69
70 1
        return $this->pimpleContainer->extend(
71 1
            $this->ensureNamespacesLoaded($id), $callable
72 1
        );
73
    }
74
75
    public function keys()
76
    {
77
        return $this->pimpleContainer->keys();
78
    }
79
80
    public function register(ServiceProviderInterface $provider, array $values = array())
81
    {
82
        return $this->pimpleContainer->register($provider, $values);
83
    }
84
85 9
    public function registerServiceProviderProvider(ServiceProviderProviderInterface $providerProvider)
86
    {
87 9
        foreach ($providerProvider->provideServiceProviders($this) as $nameSpace => $serviceProvider) {
88 9
            if (isset($this->namespaceProviders[$nameSpace])) {
89 1
                throw new \RuntimeException('Can\'t redefine serviceProvider for namespace ' . $nameSpace);
90
            }
91
92 9
            if (!is_string($nameSpace)) {
93 1
                throw new \RuntimeException('Namespace must be a string');
94
            }
95
96 8
            if (! $serviceProvider instanceof ServiceProviderInterface) {
97 1
                throw new \RuntimeException('ServiceProviderProvider must provide map of ServiceProviders');
98
            }
99
100 7
            $this->namespaceProviders[$nameSpace] = $serviceProvider;
101 7
        }
102 7
    }
103
104 6
    protected function loadNamespace($name)
105
    {
106 6
        if (in_array($name, $this->loadedNamespaces)) {
107 2
            return;
108 3
        }
109
110 6
        if (! isset($this->namespaceProviders[$name])) {
111 1
            throw new \InvalidArgumentException('No providerProvider registered for namespace ' . $name);
112
        }
113
114 5
        $this->namespaceProviders[$name]->register($this);
115 5
        $this->loadedNamespaces[] = $name;
116 5
    }
117
118 7
    protected function ensureNamespacesLoaded($id)
119
    {
120 7
        if (($split = strpos($id, '::')) !== false) {
121 6
            $this->loadNameSpace(substr($id, 0, $split));
122 5
        }
123
124 6
        return $id;
125
    }
126
}
127