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

Snidel_Error   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Error::offsetExists() 0 8 3
A Error::offsetGet() 0 8 2
A Error::offsetSet() 0 4 1
A Error::offsetUnset() 0 4 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