ParamBag   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 143
ccs 0
cts 44
cp 0
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 4 1
A __get() 0 4 2
A __isset() 0 4 1
A __set() 0 4 1
A __unset() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A getIterator() 0 4 1
1
<?php
2
3
/**
4
 * @author    Flipbox Factory
5
 * @copyright Copyright (c) 2017, Flipbox Digital
6
 * @link      https://github.com/flipbox/transform/releases/latest
7
 * @license   https://github.com/flipbox/transform/blob/master/LICENSE
8
 */
9
10
namespace Flipbox\Transform;
11
12
use ArrayAccess;
13
use IteratorAggregate;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 3.0.0
18
 */
19
class ParamBag implements ArrayAccess, IteratorAggregate
20
{
21
    /**
22
     * @var array
23
     */
24
    protected $params = [];
25
26
    /**
27
     * @param array $params
28
     */
29
    public function __construct(array $params)
30
    {
31
        $this->params = $params;
32
    }
33
34
    /**
35
     * Get parameter values out of the bag.
36
     *
37
     * @param string $key
38
     *
39
     * @return mixed
40
     */
41
    public function get($key)
42
    {
43
        return $this->__get($key);
44
    }
45
46
    /**
47
     * Get parameter values out of the bag via the property access magic method.
48
     *
49
     * @param string $key
50
     *
51
     * @return mixed
52
     */
53
    public function __get($key)
54
    {
55
        return isset($this->params[$key]) ? $this->params[$key] : null;
56
    }
57
58
    /**
59
     * Check if a param exists in the bag via an isset() check on the property.
60
     *
61
     * @param string $key
62
     *
63
     * @return bool
64
     */
65
    public function __isset($key)
66
    {
67
        return isset($this->params[$key]);
68
    }
69
70
    /**
71
     * Disallow changing the value of params in the data bag via property access.
72
     *
73
     * @param string $key
74
     * @param mixed $value
75
     *
76
     * @throws \LogicException
77
     *
78
     * @return void
79
     */
80
    public function __set($key, $value)
81
    {
82
        throw new \LogicException('Modifying parameters is not permitted');
83
    }
84
85
    /**
86
     * Disallow unsetting params in the data bag via property access.
87
     *
88
     * @param string $key
89
     *
90
     * @throws \LogicException
91
     *
92
     * @return void
93
     */
94
    public function __unset($key)
95
    {
96
        throw new \LogicException('Modifying parameters is not permitted');
97
    }
98
99
    /**
100
     * Check if a param exists in the bag via an isset() and array access.
101
     *
102
     * @param string $key
103
     *
104
     * @return bool
105
     */
106
    public function offsetExists($key)
107
    {
108
        return $this->__isset($key);
109
    }
110
111
    /**
112
     * Get parameter values out of the bag via array access.
113
     *
114
     * @param string $key
115
     *
116
     * @return mixed
117
     */
118
    public function offsetGet($key)
119
    {
120
        return $this->__get($key);
121
    }
122
123
    /**
124
     * Disallow changing the value of params in the data bag via array access.
125
     *
126
     * @param string $key
127
     * @param mixed $value
128
     *
129
     * @throws \LogicException
130
     *
131
     * @return void
132
     */
133
    public function offsetSet($key, $value)
134
    {
135
        throw new \LogicException('Modifying parameters is not permitted');
136
    }
137
138
    /**
139
     * Disallow unsetting params in the data bag via array access.
140
     *
141
     * @param string $key
142
     *
143
     * @throws \LogicException
144
     *
145
     * @return void
146
     */
147
    public function offsetUnset($key)
148
    {
149
        throw new \LogicException('Modifying parameters is not permitted');
150
    }
151
152
    /**
153
     * IteratorAggregate for iterating over the object like an array.
154
     *
155
     * @return \ArrayIterator
156
     */
157
    public function getIterator()
158
    {
159
        return new \ArrayIterator($this->params);
160
    }
161
}
162