Completed
Push — master ( 8726a2...c500ff )
by Tim
01:40
created

TestData::setInput()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 14
rs 8.8571
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
final class TestData
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $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 array $input
23
     * @param string $key
0 ignored issues
show
Documentation introduced by
Should the type for parameter $key not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
24
     *
25
     * @return void
26
     */
27
    public function setInput($input = array(), $key = null)
28
    {
29
        assert(is_array($input));
30
        assert(is_string($key) || is_null($key));
31
        if (is_null($key)) {
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
     * @param string|null $item
61
     *
62
     * @return mixed
63
     */
64
    protected function getInput($item = null)
65
    {
66
        assert(is_string($item) || is_null($item));
67
        return is_null($item) ? $this->testData : (isSet($this->testData[$item]) ? $this->testData[$item] : null);
68
    }
69
}
70