Completed
Branch master (f51f05)
by Ilias
05:09
created

Container::protect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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 9
    public function __construct(array $values = array())
21
    {
22 9
        $this->pimpleContainer = new \Pimple\Container($values);
23 9
    }
24
25 6
    public function offsetSet($id, $value)
26
    {
27 6
        $this->pimpleContainer->offsetSet($id, $value);
28 6
    }
29
30 5 View Code Duplication
    public function offsetGet($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32 5
        if (($split = strpos($id, '::')) !== false) {
33 4
            $this->loadNameSpace(substr($id, 0, $split));
34 3
        }
35
36 4
        return $this->pimpleContainer->offsetGet($id);
37
    }
38
39 1 View Code Duplication
    public function offsetExists($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 1
        if (($split = strpos($id, '::')) !== false) {
42 1
            $this->loadNameSpace(substr($id, 0, $split));
43 1
        }
44
45 1
        return $this->pimpleContainer->offsetExists($id);
46
    }
47
48
    public function offsetUnset($id)
49
    {
50
        $this->pimpleContainer->offsetUnset($id);
51
    }
52
53
    public function factory($callable)
54
    {
55
        return $this->pimpleContainer->factory($callable);
56
    }
57
58
    public function protect($callable)
59
    {
60
        return $this->pimpleContainer->protect($callable);
61
    }
62
63 1 View Code Duplication
    public function raw($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 1
        if (($split = strpos($id, '::')) !== false) {
66 1
            $this->loadNameSpace(substr($id, 0, $split));
67 1
        }
68
69 1
        return $this->pimpleContainer->raw($id);
70
    }
71
72 1 View Code Duplication
    public function extend($id, $callable)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74 1
        if (($split = strpos($id, '::')) !== false) {
75 1
            $this->loadNameSpace(substr($id, 0, $split));
76 1
        }
77
78 1
        return $this->pimpleContainer->extend($id, $callable);
79
    }
80
81
    public function keys()
82
    {
83
        return $this->pimpleContainer->keys();
84
    }
85
86
    public function register(ServiceProviderInterface $provider, array $values = array())
87
    {
88
        return $this->pimpleContainer->register($provider, $values);
89
    }
90
91 7
    public function registerServiceProviderProvider(ServiceProviderProviderInterface $providerProvider)
92
    {
93 7
        foreach ($providerProvider->provideServiceProviders($this) as $nameSpace => $serviceProvider) {
94 7
            if (isset($this->namespaceProviders[$nameSpace])) {
95 1
                throw new \RuntimeException('Can\'t redefine serviceProvider for namespace ' . $nameSpace);
96
            }
97
98 7
            $this->namespaceProviders[$nameSpace] = $serviceProvider;
99 7
        }
100 7
    }
101
102 6
    protected function loadNamespace($name)
103
    {
104 6
        if (in_array($name, $this->loadedNamespaces)) {
105 2
            return;
106
        }
107
108 6
        if (! isset($this->namespaceProviders[$name])) {
109 1
            throw new \InvalidArgumentException('No providerProvider registered for namespace ' . $name);
110
        }
111
112 5
        $this->namespaceProviders[$name]->register($this);
113 5
        $this->loadedNamespaces[] = $name;
114 5
    }
115
}
116