Code Duplication    Length = 60-65 lines in 2 locations

lib/TestData.php 1 location

@@ 5-69 (lines=65) @@
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 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
     * @param string|null $item
61
     *
62
     * @return mixed
63
     */
64
    public 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

lib/TestResult.php 1 location

@@ 5-64 (lines=60) @@
2
3
namespace SimpleSAML\Module\monitor;
4
5
final class TestResult
6
{
7
    /**
8
     * @param array $output
9
     */
10
    public function __construct($output = array())
11
    {
12
        assert(is_array($output));
13
        $this->setInput($output);
14
    }
15
16
    /**
17
     * @param mixed|null $output
18
     * @param string|null $key
19
     *
20
     * @return void
21
     */
22
    public function setOutput($output, $key = null)
23
    {
24
        assert(is_string($key) || is_null($key));
25
        if (is_null($key)) {
26
            assert(is_array($output));
27
            foreach ($output as $key => $value) {
28
                $this->addOutput($key, $value);
29
            }
30
        } elseif (array_key_exists($key, $this->output)) {
31
            $this->output[$key] = $output;
32
        } else {
33
            $this->addOutput($key, $output);
34
        }
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed|null $value
40
     *
41
     * @return void
42
     */
43
    public function addOutput($key, $value = null)
44
    {
45
        assert(is_string($key));
46
        if (isSet($this->output[$key])) {
47
            assert(is_array($this->output[$key]));
48
            $this->output[$key] = array_merge($this->output[$key], $value);
49
        } else {
50
            $this->output[$key] = $value;
51
        }
52
    }
53
54
    /**
55
     * @param string|null $item
56
     *
57
     * @return mixed
58
     */
59
    public function getOutput($item = null)
60
    {
61
        assert(is_string($item) || is_null($item));
62
        return is_null($item) ? $this->output : (isSet($this->output[$item]) ? $this->output[$item] : null);
63
    }
64
}
65