Completed
Push — master ( 4e273e...e5332e )
by Adrian
02:17
created

DataContainer   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 95%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 34
ccs 19
cts 20
cp 0.95
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAll() 0 4 1
A get() 0 6 2
B set() 0 18 7
1
<?php
2
namespace Sirius\Input;
3
4
class DataContainer extends \ArrayObject
5
{
6
7 42
    public function set($nameOrArray, $value = null)
8
    {
9 42
        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 42
        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 42
        if ($value !== null) {
20 42
            $this[$nameOrArray] = $value;
21 42
        } elseif ($value === null && isset($this[$nameOrArray])) {
22 3
            unset($this[$nameOrArray]);
23 3
        }
24 42
    }
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
}