Completed
Branch master (740422)
by Mathieu
02:04
created

Container   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
dl 0
loc 55
ccs 3
cts 6
cp 0.5
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 14 3
A offsetSet() 0 4 1
A offsetUnset() 0 6 2
A setWarehouse() 0 6 1
1
<?php
2
namespace Suricate;
3
4
class Container implements \ArrayAccess
5
{
6
    private $content;
7
    private $warehouse;
8
9
    public function __construct(array $values = array())
10
    {
11
        $this->content = $values;
12
    }
13
14
    public function offsetExists($offset)
15
    {
16
        return isset($this->content[$offset]);
17
    }
18
19 1
    public function offsetGet($offset)
20
    {
21
        if (isset($this->content[$offset])) {
22
            return $this->content[$offset];
23
        } else {
24 1
            if (isset($this->warehouse[$offset])) {
25
                $this->content[$offset] = new $this->warehouse[$offset]();
26 1
                return $this->content[$offset];
27
            } else {
28
                throw new \InvalidArgumentException('Unknown service ' . $offset);
29
            }
30
            
31
        }
32
    }
33
34
    public function offsetSet($offset, $value)
35
    {
36
37
    }
38
39
    public function offsetUnset($offset)
40
    {
41
        if (isset($this->content[$offset])) {
42
            unset($this->content[$offset]);
43
        }
44
    }
45
46
    public function setWarehouse($serviceList)
47
    {
48
        $this->warehouse = $serviceList;
49
50
        return $this;
51
    }
52
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
    public function getServiceNameList()
54
    {
55
        return array_keys($this->content);
56
    }
57
    */
58
}
59