InputContainer   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 81
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 7 2
A has() 0 4 1
A getArrayCopy() 0 4 1
A offsetExists() 0 4 1
A offsetSet() 0 4 1
A offsetGet() 0 4 2
A offsetUnset() 0 6 2
1
<?php
2
namespace Germania\FormValidator;
3
4
use Psr\Container\ContainerInterface;
5
6
class InputContainer implements ContainerInterface, \ArrayAccess
7
{
8
9
    /**
10
     * @var array
11
     */
12
    public $data;
13
14
    /**
15
     * @param array $data     Input values (optional)
16
     * @param array $defaults Default values (optional)
17
     */
18 55
    public function __construct( array $data = array(), array $defaults = array() )
19
    {
20 55
        $this->data = array_merge($defaults, $data);
21 55
    }
22
23
24
    /**
25
     * @implements ContainerInterface
26
     */
27 10
    public function get( $offset )
28
    {
29 10
        if ($this->offsetExists( $offset )) {
30 5
            return $this->data[ $offset ];
31
        }
32 5
        throw new NotFoundException;
33
    }
34
35
    /**
36
     * @implements ContainerInterface
37
     */
38 15
    public function has( $offset )
39
    {
40 15
        return $this->offsetExists( $offset );
41
    }
42
43
44
    /**
45
     * @return array
46
     */
47
    public function getArrayCopy()
48
    {
49 20
        return $this->data;        
50
    }
51 20
52
53
    /**
54
     * @implements ArrayAccess
55
     */
56
    public function offsetExists($offset)
57
    {
58
        return isset($this->data[ $offset ]);
59
    }
60
61
    /**
62
     * @implements ArrayAccess
63
     */
64
    public function offsetSet($offset, $value)
65 15
    {
66
        $this->data[ $offset ] = $value;
67 15
    }
68
69
    /**
70
     * @implements ArrayAccess
71
     */
72
    public function offsetGet($offset)
73
    {
74
        return $this->offsetExists( $offset ) ? $this->data[ $offset ] : null;
75
    }
76
77
    /**
78
     * @implements ArrayAccess
79
     */
80
    public function offsetUnset($offset)
81
    {
82
        if ($this->offsetExists($offset)) {
83
            unset($this->data[ $offset ]);
84
        }
85
    }
86
}
87