DataContainer::set()   B
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 7.0178

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 14
cp 0.9286
rs 8.2222
cc 7
eloc 11
nc 6
nop 2
crap 7.0178
1
<?php
2
namespace Sirius\Input;
3
4
class DataContainer extends \ArrayObject
5
{
6
7 43
    public function set($nameOrArray, $value = null)
8
    {
9 43
        if (is_array($nameOrArray)) {
10 12
            foreach ($nameOrArray as $k => $v) {
11 12
                $this->set($k, $v);
12 12
            }
13
14 12
            return;
15
        }
16 43
        if (!is_string($nameOrArray)) {
17
            throw new \InvalidArgumentException('Only strings or arrays are accepted as first argument of the set() method of the DataContainer class');
18
        }
19 43
        if ($value !== null) {
20 43
            $this[$nameOrArray] = $value;
21 43
        } elseif ($value === null && isset($this[$nameOrArray])) {
22 3
            unset($this[$nameOrArray]);
23 3
        }
24 43
    }
25
26 10
    public function get($name)
27
    {
28 10
        return isset($this[$name])
29 10
            ? $this[$name]
30 10
            : null;
31
    }
32
33 5
    public function getAll()
34
    {
35 5
        return $this->getArrayCopy();
36
    }
37
}