Completed
Push — master ( 526d6e...2376dc )
by Akihito
03:04
created

Error::offsetGet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
namespace Ackintosh\Snidel;
3
4
class Error implements \ArrayAccess
5
{
6
    /** #var array */
7
    private $errors = array();
8
9
    /**
10
     * @param   mixed   $offset
11
     * @return  bool
12
     */
13
    public function offsetExists($offset)
14
    {
15
        if (isset($this->errors[$offset]) && $this->errors[$offset] !== '') {
16
            return true;
17
        }
18
19
        return false;
20
    }
21
22
    /**
23
     * @param   mixed   $offset
24
     * @return  mixed
25
     */
26
    public function offsetGet($offset)
27
    {
28
        if (!$this->offsetExists($offset)) {
29
            return null;
30
        }
31
32
        return $this->errors[$offset];
33
    }
34
35
    /**
36
     * @param   mixed   $offset
37
     * @return  void
38
     */
39
    public function offsetSet($offset, $value)
40
    {
41
        $this->errors[$offset] = $value;
42
    }
43
44
    /**
45
     * @param   mixed   $offset
46
     * @return  void
47
     */
48
    public function offsetUnset($offset)
49
    {
50
        unset($this->errors[$offset]);
51
    }
52
53
    /**
54
     * @return  bool
55
     */
56
    public function exists()
57
    {
58
        return count($this->errors) > 0;
59
    }
60
}
61