Completed
Branch feature-unit-tests (9d0273)
by Tim
01:44
created

TestData   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addInput() 0 8 2
A __construct() 0 4 1
B setInput() 0 12 5
A getInputItem() 0 3 2
A getInput() 0 3 1
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
final class TestData
6
{
7
    /**
8
     * @var array
9
     */
10
    private $testData = array();
11
12
    /**
13
     * @param array $input
14
     */
15
    public function __construct($input = array())
16
    {
17
        assert(is_array($input));
18
        $this->setInput($input);
19
    }
20
21
    /**
22
     * @param mixed|null $input
23
     * @param string|null $key
24
     *
25
     * @return void
26
     */
27
    public function setInput($input, $key = null)
28
    {
29
        assert(is_string($key) || is_null($key));
30
        if (is_null($key)) {
31
            assert(is_array($input));
32
            foreach ($input as $key => $value) {
33
                $this->addInput($key, $value);
34
            }
35
        } elseif (array_key_exists($key, $this->testData)) {
36
            $this->testData[$key] = $input;
37
        } else {
38
            $this->addInput($key, $input);
39
        }
40
    }
41
42
    /**
43
     * @param string $key
44
     * @param mixed|null $value
45
     *
46
     * @return void
47
     */
48
    public function addInput($key, $value = null)
49
    {
50
        assert(is_string($key));
51
        if (isSet($this->testData[$key])) {
52
            assert(is_array($this->testData[$key]));
53
            $this->testData[$key] = array_merge($this->testData[$key], $value);
54
        } else {
55
            $this->testData[$key] = $value;
56
        }
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function getInput()
63
    {
64
        return $this->testData;
65
    }
66
67
    /**
68
     * @param string $item
69
     *
70
     * @return mixed|null
71
     */
72
    public function getInputItem($item) {
73
        assert(is_string($item));
74
        return array_key_exists($item, $this->testData) ? $this->testData[$item] : null;
75
    }
76
}
77