Completed
Push — master ( b2f154...4a7b6a )
by Tim
01:53
created

TestFactory::setCategory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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