Completed
Push — develop ( a14d83...6bfc05 )
by Mathieu
01:47
created

Container::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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