1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kolyunya\Codeception\Lib\MarkupValidator; |
4
|
|
|
|
5
|
|
|
use Kolyunya\Codeception\Lib\MarkupValidator\MarkupValidatorMessageInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Base markup validator message. |
9
|
|
|
*/ |
10
|
|
|
class MarkupValidatorMessage implements MarkupValidatorMessageInterface |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Message type. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $type; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Message summary. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $summary; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Message details. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $details; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* A number of the first related markup line. |
35
|
|
|
* |
36
|
|
|
* @var integer |
37
|
|
|
*/ |
38
|
|
|
protected $firstLineNumber; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* A number of the last related markup line. |
42
|
|
|
* |
43
|
|
|
* @var integer |
44
|
|
|
*/ |
45
|
|
|
protected $lastLineNumber; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Related markup. |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $markup; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Constructs a new message. Sets message type. |
56
|
|
|
* |
57
|
|
|
* @param string $type Message type. |
58
|
|
|
*/ |
59
|
|
|
public function __construct($type = self::TYPE_UNDEFINED) |
60
|
|
|
{ |
61
|
|
|
$this->setType($type); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritDoc} |
66
|
|
|
*/ |
67
|
|
|
public function __toString() |
68
|
|
|
{ |
69
|
|
|
return vsprintf($this->getStringTemplate(), array( |
70
|
|
|
$this->getType() ?: 'unavailable', |
71
|
|
|
$this->getSummary() ?: 'unavailable', |
72
|
|
|
$this->getDetails() ?: 'unavailable', |
73
|
|
|
$this->getMarkup() ?: 'unavailable', |
74
|
|
|
)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sets message type. |
79
|
|
|
* |
80
|
|
|
* @param string $type Message type. |
81
|
|
|
* |
82
|
|
|
* @return self Returns self. |
83
|
|
|
*/ |
84
|
|
|
public function setType($type) |
85
|
|
|
{ |
86
|
|
|
if ($type === null) { |
87
|
|
|
$type = self::TYPE_UNDEFINED; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->type = $type; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritDoc} |
97
|
|
|
*/ |
98
|
|
|
public function getType() |
99
|
|
|
{ |
100
|
|
|
return $this->type; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Sets message summary. |
105
|
|
|
* |
106
|
|
|
* @param string $summary Message summary. |
107
|
|
|
* |
108
|
|
|
* @return self Returns self. |
109
|
|
|
*/ |
110
|
|
|
public function setSummary($summary) |
111
|
|
|
{ |
112
|
|
|
$this->summary = $summary; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritDoc} |
119
|
|
|
*/ |
120
|
|
|
public function getSummary() |
121
|
|
|
{ |
122
|
|
|
return $this->summary; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Sets message details. |
127
|
|
|
* |
128
|
|
|
* @param string $details Message details. |
129
|
|
|
* |
130
|
|
|
* @return self Returns self. |
131
|
|
|
*/ |
132
|
|
|
public function setDetails($details) |
133
|
|
|
{ |
134
|
|
|
$this->details = $details; |
135
|
|
|
|
136
|
|
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* {@inheritDoc} |
141
|
|
|
*/ |
142
|
|
|
public function getDetails() |
143
|
|
|
{ |
144
|
|
|
return $this->details; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Sets first line number. |
149
|
|
|
* |
150
|
|
|
* @param string $firstLineNumber First line number. |
151
|
|
|
* |
152
|
|
|
* @return self Returns self. |
153
|
|
|
*/ |
154
|
|
|
public function setFirstLineNumber($firstLineNumber) |
155
|
|
|
{ |
156
|
|
|
$this->firstLineNumber = $firstLineNumber; |
|
|
|
|
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* {@inheritDoc} |
163
|
|
|
*/ |
164
|
|
|
public function getFirstLineNumber() |
165
|
|
|
{ |
166
|
|
|
return $this->firstLineNumber; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Sets last line number. |
171
|
|
|
* |
172
|
|
|
* @param string $lastLineNumber Last line number. |
173
|
|
|
* |
174
|
|
|
* @return self Returns self. |
175
|
|
|
*/ |
176
|
|
|
public function setLastLineNumber($lastLineNumber) |
177
|
|
|
{ |
178
|
|
|
$this->lastLineNumber = $lastLineNumber; |
|
|
|
|
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* {@inheritDoc} |
185
|
|
|
*/ |
186
|
|
|
public function getLastLineNumber() |
187
|
|
|
{ |
188
|
|
|
return $this->lastLineNumber; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Sets markup. |
193
|
|
|
* |
194
|
|
|
* @param string $markup Markup. |
195
|
|
|
* |
196
|
|
|
* @return self Returns self. |
197
|
|
|
*/ |
198
|
|
|
public function setMarkup($markup) |
199
|
|
|
{ |
200
|
|
|
$this->markup = $markup; |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* {@inheritDoc} |
207
|
|
|
*/ |
208
|
|
|
public function getMarkup() |
209
|
|
|
{ |
210
|
|
|
return $this->markup; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Returns string representation template. |
215
|
|
|
* |
216
|
|
|
* @return string String representation template. |
217
|
|
|
*/ |
218
|
|
|
protected function getStringTemplate() |
219
|
|
|
{ |
220
|
|
|
return |
221
|
|
|
<<<TXT |
222
|
|
|
Markup validator message: |
223
|
|
|
Type: %s |
224
|
|
|
Summary: %s |
225
|
|
|
Details: %s |
226
|
|
|
Markup: %s |
227
|
|
|
|
228
|
|
|
TXT |
229
|
|
|
; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.