Completed
Push — master ( e0fb57...7519fb )
by Tim
09:19 queued 07:48
created

TestFactory::getOutput()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 3
nc 4
nop 1
dl 0
loc 5
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestFactory
6
{
7
    /**
8
     * @var TestData|null
9
     */
10
    private $testData = null;
11
12
    /**
13
     * @var TestConfiguration|null
14
     */
15
    private $configuration = null;
16
17
    /**
18
     * @var array|null
19
     */
20
    private $output = array();
21
22
    /**
23
     * @var State
24
     */
25
    private $state = State::NOSTATE;
26
27
    /**
28
     * @var array
29
     */
30
    private $messages = array();
31
32
33
    /**
34
     * @param TestConfiguration|null $configuration
35
     *
36
     * @return void
37
     */
38
    protected function setConfiguration($configuration = null)
39
    {
40
        assert($configuration instanceof TestConfiguration);
41
        if (!is_null($configuration)) {
42
            $this->configuration = $configuration;
43
        }
44
    }
45
46
47
    /**
48
     * @return TestConfiguration
49
     */
50
    public function getConfiguration()
51
    {
52
        assert($this->configuration instanceof TestConfiguration);
53
        return $this->configuration;
54
    }
55
56
57
    /**
58
     * @return TestData|null
59
     */
60
    public function getTestData()
61
    {
62
        assert($this->testData instanceof TestData || is_null($this->testData));
63
        return $this->testData;
64
    }
65
66
67
    /**
68
     * @param TestData|null $testData
69
     *
70
     * @return void
71
     */
72
    protected function setTestData($testData = null)
73
    {
74
        assert($testData instanceof TestData || is_null($testData));
75
        if (!is_null($testData)) {
76
            $this->testData = $testData;
77
        }
78
    }
79
80
81
    /**
82
     * @return array
83
     */
84
    public function getMessages()
85
    {
86
        assert(is_array($this->messages));
87
        return $this->messages;
88
    }
89
90
91
    /**
92
     * @param string|null $item
93
     *
94
     * @return mixed
95
     */
96
    public function getOutput($item = null)
97
    {
98
        assert(is_string($item) || is_null($item));
99
        return is_null($item) ? $this->output : (isSet($this->output[$item]) ? $this->output[$item] : null);
100
    }
101
102
103
    /**
104
     * @return State
105
     */
106
    public function getState()
107
    {
108
        assert($this->state instanceof State);
109
        return $this->state;
110
    }
111
112
113
    /**
114
     * @return void
115
     */
116
    protected function setMessages($messages)
117
    {
118
        assert(is_array($messages));
119
        $this->messages = $messages;
120
    }
121
122
123
    /**
124
     * @param array $messages
125
     * @param string|null $index
126
     *
127
     * @return void
128
     */
129
    protected function addMessages($messages, $index = null)
130
    {
131
        if ($index === null) {
132
            $this->messages = array_merge($this->messages, $messages);
133
        } else {
134
            foreach ($messages as $message) {
135
                $this->messages[$index][] = $message;
136
            }
137
        }
138
    }
139
140
141
    /**
142
     * @param State $state
143
     * @param string $category
144
     * @param string $subject
145
     * @param string $message
146
     *
147
     * @return void
148
     */
149
    protected function addMessage($state, $category, $subject, $message)
150
    {
151
        assert(($state instanceof State) && is_string($category) && is_string($subject) && is_string($message));
152
        $this->messages[] = array($state, $category, $subject, $message);
153
    }
154
155
156
    /**
157
     * @param mixed $value
158
     * @param string|null $index
159
     *
160
     * @return void
161
     */
162
    protected function addOutput($value, $index = null)
163
    {
164
        if ($index === null) {
165
            $this->output = array_merge($this->output, $value);
166
        } else {
167
            $this->output[$index] = $value;
168
        }
169
    }
170
171
172
    /**
173
     * @return void
174
     */
175
    protected function setOutput($output)
176
    {
177
        assert(is_array($output));
178
        $this->output = $output;
179
    }
180
181
182
    /**
183
     * @return void
184
     */
185
    protected function setState($state)
186
    {
187
        assert($state instanceof State);
188
        $this->state = $state;
189
    }
190
}
191