Container   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 15
c 3
b 1
f 0
dl 0
loc 78
ccs 21
cts 21
cp 1
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setWarehouse() 0 5 1
A offsetUnset() 0 4 2
A offsetExists() 0 3 1
A __construct() 0 3 1
A offsetSet() 0 2 1
A offsetGet() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Suricate;
6
7
class Container implements \ArrayAccess
8
{
9
    private $content;
10
    private $warehouse = [];
11
12 13
    public function __construct(array $values = [])
13
    {
14 13
        $this->content = $values;
15 13
    }
16
17
    /**
18
     * \ArrayAccess offsetExists implementation
19
     *
20
     * @param mixed $offset offset to check
21
     * @return bool
22
     */
23 3
    public function offsetExists($offset)
24
    {
25 3
        return isset($this->content[$offset]);
26
    }
27
28
    /**
29
     * \ArrayAccess offsetGet implementation
30
     *
31
     * @param mixed $offset offset to get
32
     * @throws \InvalidArgumentException
33
     * @return bool
34
     */
35 22
    public function offsetGet($offset)
36
    {
37 22
        if (isset($this->content[$offset])) {
38 20
            return $this->content[$offset];
39
        }
40
41
        // Instantiate from warehouse if available
42 12
        if (isset($this->warehouse[$offset])) {
43 11
            $this->content[$offset] = new $this->warehouse[$offset]();
44 11
            return $this->content[$offset];
45
        }
46
47 1
        throw new \InvalidArgumentException('Unknown service ' . $offset);
48
    }
49
50
    /**
51
     * \ArrayAccess offsetSet implementation
52
     *
53
     * @param mixed $offset offset to set
54
     * @param mixed $value  value to set
55
     * @return void
56
     */
57 1
    public function offsetSet($offset, $value)
58
    {
59 1
    }
60
61
    /**
62
     * \ArrayAccess offsetUnset implementation
63
     *
64
     * @param mixed $offset offset to unset
65
     * @return void
66
     */
67 1
    public function offsetUnset($offset)
68
    {
69 1
        if (isset($this->content[$offset])) {
70 1
            unset($this->content[$offset]);
71
        }
72 1
    }
73
74
    /**
75
     * Set warehouse array
76
     *
77
     * @param array $serviceList warehouse content
78
     * @return Container
79
     */
80 10
    public function setWarehouse(array $serviceList)
81
    {
82 10
        $this->warehouse = $serviceList;
83
84 10
        return $this;
85
    }
86
}
87