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

Container   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 107
Duplicated Lines 29.91 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 78.85%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
c 1
b 0
f 0
lcom 1
cbo 3
dl 32
loc 107
ccs 41
cts 52
cp 0.7885
rs 10

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetSet() 0 4 1
A offsetGet() 8 8 2
A offsetExists() 8 8 2
A offsetUnset() 0 4 1
A factory() 0 4 1
A protect() 0 4 1
A raw() 8 8 2
A extend() 8 8 2
A keys() 0 4 1
A register() 0 4 1
A registerServiceProviderProvider() 0 10 3
A loadNamespace() 0 13 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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