Completed
Push — master ( 60aec0...f632bc )
by Andreas
12:47 queued 10:41
created

ParamsBag::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Larium\Pay;
4
5
use Iterator;
6
use ArrayAccess;
7
8
class ParamsBag implements Iterator, ArrayAccess
9
{
10
    /**
11
     * The array of option values.
12
     *
13
     * @var array
14
     */
15
    private $params = array();
16
17 7
    public function __construct(array $params = array())
18
    {
19 7
        $this->params = $params;
20
    }
21
22 7
    public function get($name, $default = null)
23
    {
24
        return $this->offsetExists($name)
25
            ? $this->offsetGet($name)
26 7
            : $default;
27
    }
28
29
    public function __get($name)
30
    {
31
        return $this->offsetGet($name);
32
    }
33
34
    public function __set($name, $value)
35
    {
36
        $this->offsetSet($name, $value);
37
    }
38
39
    public function __isset($name)
40
    {
41
        return $this->offsetExists($name);
42
    }
43
44
    /**
45
     * Returns an array from params.
46
     *
47
     * @return array
48
     */
49
    public function getArrayCopy()
50
    {
51
        return $this->params;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function rewind()
58
    {
59
        reset($this->params);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function current()
66
    {
67
        return current($this->params);
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function key()
74
    {
75
        return key($this->params);
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function next()
82
    {
83
        next($this->params);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function valid()
90
    {
91
        return current($this->params) !== false;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97
    public function offsetSet($offset, $value)
98
    {
99
        if (is_null($offset)) {
100
            $this->params[] = $value;
101
        } else {
102
            $this->params[$offset] = $value;
103
        }
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function offsetExists($offset)
110
    {
111
        return array_key_exists($offset, $this->params);
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    public function offsetUnset($offset)
118
    {
119
        unset($this->params[$offset]);
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 1
    public function offsetGet($offset)
126
    {
127 1
        $value = isset($this->params[$offset])
128 1
            ? $this->params[$offset]
129 1
            : null;
130
131
        if (is_array($value)) {
132
            return new self($value);
133
        }
134
135 1
        return $value;
136
    }
137
}
138