@@ -61,50 +61,50 @@ discard block |
||
61 | 61 | |
62 | 62 | const ERROR_NOT_A_SINGLE_LINES_FORMATTER = 47806; |
63 | 63 | |
64 | - /** |
|
65 | - * @var Mailcode_Parser |
|
66 | - */ |
|
64 | + /** |
|
65 | + * @var Mailcode_Parser |
|
66 | + */ |
|
67 | 67 | protected $parser; |
68 | 68 | |
69 | - /** |
|
70 | - * @var Mailcode_Collection |
|
71 | - */ |
|
69 | + /** |
|
70 | + * @var Mailcode_Collection |
|
71 | + */ |
|
72 | 72 | protected $commands; |
73 | 73 | |
74 | - /** |
|
75 | - * @var string |
|
76 | - */ |
|
74 | + /** |
|
75 | + * @var string |
|
76 | + */ |
|
77 | 77 | protected $originalString; |
78 | 78 | |
79 | - /** |
|
80 | - * @var Mailcode_Collection |
|
81 | - */ |
|
79 | + /** |
|
80 | + * @var Mailcode_Collection |
|
81 | + */ |
|
82 | 82 | protected $collection; |
83 | 83 | |
84 | - /** |
|
85 | - * Counter for the placeholders, global for all placeholders. |
|
86 | - * @var integer |
|
87 | - */ |
|
84 | + /** |
|
85 | + * Counter for the placeholders, global for all placeholders. |
|
86 | + * @var integer |
|
87 | + */ |
|
88 | 88 | private static $counter = 0; |
89 | 89 | |
90 | - /** |
|
91 | - * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
92 | - */ |
|
90 | + /** |
|
91 | + * @var Mailcode_Parser_Safeguard_Placeholder[] |
|
92 | + */ |
|
93 | 93 | protected $placeholders; |
94 | 94 | |
95 | - /** |
|
96 | - * @var string |
|
97 | - */ |
|
95 | + /** |
|
96 | + * @var string |
|
97 | + */ |
|
98 | 98 | protected $delimiter = '__'; |
99 | 99 | |
100 | - /** |
|
101 | - * @var string[]|NULL |
|
102 | - */ |
|
100 | + /** |
|
101 | + * @var string[]|NULL |
|
102 | + */ |
|
103 | 103 | protected $placeholderStrings; |
104 | 104 | |
105 | - /** |
|
106 | - * @var Mailcode_Parser_Safeguard_Formatter |
|
107 | - */ |
|
105 | + /** |
|
106 | + * @var Mailcode_Parser_Safeguard_Formatter |
|
107 | + */ |
|
108 | 108 | protected $formatter; |
109 | 109 | |
110 | 110 | public function __construct(Mailcode_Parser $parser, string $subject) |
@@ -113,25 +113,25 @@ discard block |
||
113 | 113 | $this->originalString = $subject; |
114 | 114 | } |
115 | 115 | |
116 | - /** |
|
117 | - * Retrieves the string the safeguard was created for. |
|
118 | - * |
|
119 | - * @return string |
|
120 | - */ |
|
116 | + /** |
|
117 | + * Retrieves the string the safeguard was created for. |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
121 | 121 | public function getOriginalString() : string |
122 | 122 | { |
123 | 123 | return $this->originalString; |
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * Sets the delimiter character sequence used to prepend |
|
128 | - * and append to the placeholders. |
|
129 | - * |
|
130 | - * The delimiter's default is "__" (two underscores). |
|
131 | - * |
|
132 | - * @param string $delimiter |
|
133 | - * @return Mailcode_Parser_Safeguard |
|
134 | - */ |
|
126 | + /** |
|
127 | + * Sets the delimiter character sequence used to prepend |
|
128 | + * and append to the placeholders. |
|
129 | + * |
|
130 | + * The delimiter's default is "__" (two underscores). |
|
131 | + * |
|
132 | + * @param string $delimiter |
|
133 | + * @return Mailcode_Parser_Safeguard |
|
134 | + */ |
|
135 | 135 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
136 | 136 | { |
137 | 137 | if(empty($delimiter)) |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | return $this->delimiter; |
154 | 154 | } |
155 | 155 | |
156 | - /** |
|
157 | - * Retrieves the safe string in which all commands have been replaced |
|
158 | - * by placeholder strings. |
|
159 | - * |
|
160 | - * @return string |
|
161 | - * @throws Mailcode_Exception |
|
162 | - * |
|
163 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
164 | - */ |
|
156 | + /** |
|
157 | + * Retrieves the safe string in which all commands have been replaced |
|
158 | + * by placeholder strings. |
|
159 | + * |
|
160 | + * @return string |
|
161 | + * @throws Mailcode_Exception |
|
162 | + * |
|
163 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
164 | + */ |
|
165 | 165 | public function makeSafe() : string |
166 | 166 | { |
167 | 167 | $this->requireValidCollection(); |
@@ -201,10 +201,10 @@ discard block |
||
201 | 201 | ); |
202 | 202 | } |
203 | 203 | |
204 | - /** |
|
205 | - * Enables the formatter that ensures that all commands that |
|
206 | - * @return Mailcode_Parser_Safeguard_Formatter_SingleLines |
|
207 | - */ |
|
204 | + /** |
|
205 | + * Enables the formatter that ensures that all commands that |
|
206 | + * @return Mailcode_Parser_Safeguard_Formatter_SingleLines |
|
207 | + */ |
|
208 | 208 | public function selectSingleLinesFormatter() : Mailcode_Parser_Safeguard_Formatter_SingleLines |
209 | 209 | { |
210 | 210 | $formatter = $this->selectFormatter('SingleLines'); |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | ); |
225 | 225 | } |
226 | 226 | |
227 | - /** |
|
228 | - * Retrieves an associative array with pairs of |
|
229 | - * [placeholder string => replacement text]. |
|
230 | - * |
|
231 | - * @param bool $highlighted |
|
232 | - * @return string[]string |
|
233 | - */ |
|
227 | + /** |
|
228 | + * Retrieves an associative array with pairs of |
|
229 | + * [placeholder string => replacement text]. |
|
230 | + * |
|
231 | + * @param bool $highlighted |
|
232 | + * @return string[]string |
|
233 | + */ |
|
234 | 234 | protected function getReplaces(bool $highlighted=false) : array |
235 | 235 | { |
236 | 236 | $placeholders = $this->getPlaceholders(); |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | } |
258 | 258 | |
259 | 259 | |
260 | - /** |
|
261 | - * Retrieves all placeholders that have to be added to |
|
262 | - * the subject text. |
|
263 | - * |
|
264 | - * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
265 | - */ |
|
260 | + /** |
|
261 | + * Retrieves all placeholders that have to be added to |
|
262 | + * the subject text. |
|
263 | + * |
|
264 | + * @return \Mailcode\Mailcode_Parser_Safeguard_Placeholder[] |
|
265 | + */ |
|
266 | 266 | public function getPlaceholders() |
267 | 267 | { |
268 | 268 | if(isset($this->placeholders)) |
@@ -314,17 +314,17 @@ discard block |
||
314 | 314 | return str_replace($placeholderStrings, array_values($replaces), $string); |
315 | 315 | } |
316 | 316 | |
317 | - /** |
|
318 | - * Makes the string whole again after transforming or filtering it, |
|
319 | - * by replacing the command placeholders with the original commands. |
|
320 | - * |
|
321 | - * @param string $string |
|
322 | - * @return string |
|
323 | - * @throws Mailcode_Exception |
|
324 | - * |
|
325 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
326 | - * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING |
|
327 | - */ |
|
317 | + /** |
|
318 | + * Makes the string whole again after transforming or filtering it, |
|
319 | + * by replacing the command placeholders with the original commands. |
|
320 | + * |
|
321 | + * @param string $string |
|
322 | + * @return string |
|
323 | + * @throws Mailcode_Exception |
|
324 | + * |
|
325 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
326 | + * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING |
|
327 | + */ |
|
328 | 328 | public function makeWhole(string $string) : string |
329 | 329 | { |
330 | 330 | return $this->restore( |
@@ -334,15 +334,15 @@ discard block |
||
334 | 334 | ); |
335 | 335 | } |
336 | 336 | |
337 | - /** |
|
338 | - * Like `makeWhole()`, but ignores missing command placeholders. |
|
339 | - * |
|
340 | - * @param string $string |
|
341 | - * @return string |
|
342 | - * @throws Mailcode_Exception |
|
343 | - * |
|
344 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
345 | - */ |
|
337 | + /** |
|
338 | + * Like `makeWhole()`, but ignores missing command placeholders. |
|
339 | + * |
|
340 | + * @param string $string |
|
341 | + * @return string |
|
342 | + * @throws Mailcode_Exception |
|
343 | + * |
|
344 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
345 | + */ |
|
346 | 346 | public function makeWholePartial(string $string) : string |
347 | 347 | { |
348 | 348 | return $this->restore( |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | ); |
353 | 353 | } |
354 | 354 | |
355 | - /** |
|
356 | - * Like `makeWhole()`, but replaces the commands with a syntax |
|
357 | - * highlighted version, meant for human readable texts only. |
|
358 | - * |
|
359 | - * Note: the commands lose their functionality (They cannot be |
|
360 | - * parsed from that string again). |
|
361 | - * |
|
362 | - * @param string $string |
|
363 | - * @return string |
|
364 | - * @throws Mailcode_Exception |
|
365 | - * |
|
366 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
367 | - * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING |
|
368 | - */ |
|
355 | + /** |
|
356 | + * Like `makeWhole()`, but replaces the commands with a syntax |
|
357 | + * highlighted version, meant for human readable texts only. |
|
358 | + * |
|
359 | + * Note: the commands lose their functionality (They cannot be |
|
360 | + * parsed from that string again). |
|
361 | + * |
|
362 | + * @param string $string |
|
363 | + * @return string |
|
364 | + * @throws Mailcode_Exception |
|
365 | + * |
|
366 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
367 | + * @see Mailcode_Parser_Safeguard::ERROR_COMMAND_PLACEHOLDER_MISSING |
|
368 | + */ |
|
369 | 369 | public function makeHighlighted(string $string) : string |
370 | 370 | { |
371 | 371 | return $this->restore( |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | ); |
376 | 376 | } |
377 | 377 | |
378 | - /** |
|
379 | - * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
380 | - * |
|
381 | - * @param string $string |
|
382 | - * @return string |
|
383 | - * @throws Mailcode_Exception |
|
384 | - * |
|
385 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
386 | - */ |
|
378 | + /** |
|
379 | + * Like `makeHighlighted()`, but ignores missing command placeholders. |
|
380 | + * |
|
381 | + * @param string $string |
|
382 | + * @return string |
|
383 | + * @throws Mailcode_Exception |
|
384 | + * |
|
385 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
386 | + */ |
|
387 | 387 | public function makeHighlightedPartial(string $string) : string |
388 | 388 | { |
389 | 389 | return $this->restore( |
@@ -393,11 +393,11 @@ discard block |
||
393 | 393 | ); |
394 | 394 | } |
395 | 395 | |
396 | - /** |
|
397 | - * Retrieves the commands collection contained in the string. |
|
398 | - * |
|
399 | - * @return Mailcode_Collection |
|
400 | - */ |
|
396 | + /** |
|
397 | + * Retrieves the commands collection contained in the string. |
|
398 | + * |
|
399 | + * @return Mailcode_Collection |
|
400 | + */ |
|
401 | 401 | public function getCollection() : Mailcode_Collection |
402 | 402 | { |
403 | 403 | if(isset($this->collection)) |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | return $this->getCollection()->isValid(); |
416 | 416 | } |
417 | 417 | |
418 | - /** |
|
419 | - * @throws Mailcode_Exception |
|
420 | - * |
|
421 | - * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
422 | - */ |
|
418 | + /** |
|
419 | + * @throws Mailcode_Exception |
|
420 | + * |
|
421 | + * @see Mailcode_Parser_Safeguard::ERROR_INVALID_COMMANDS |
|
422 | + */ |
|
423 | 423 | protected function requireValidCollection() : void |
424 | 424 | { |
425 | 425 | if($this->getCollection()->isValid()) |
@@ -438,11 +438,11 @@ discard block |
||
438 | 438 | ); |
439 | 439 | } |
440 | 440 | |
441 | - /** |
|
442 | - * Retrieves a list of all placeholder IDs used in the text. |
|
443 | - * |
|
444 | - * @return string[] |
|
445 | - */ |
|
441 | + /** |
|
442 | + * Retrieves a list of all placeholder IDs used in the text. |
|
443 | + * |
|
444 | + * @return string[] |
|
445 | + */ |
|
446 | 446 | public function getPlaceholderStrings() : array |
447 | 447 | { |
448 | 448 | if(is_array($this->placeholderStrings)) |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | return in_array($subject, $ids); |
470 | 470 | } |
471 | 471 | |
472 | - /** |
|
473 | - * Retrieves a placeholder instance by its ID. |
|
474 | - * |
|
475 | - * @param int $id |
|
476 | - * @throws Mailcode_Exception If the placeholder was not found. |
|
477 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
478 | - */ |
|
472 | + /** |
|
473 | + * Retrieves a placeholder instance by its ID. |
|
474 | + * |
|
475 | + * @param int $id |
|
476 | + * @throws Mailcode_Exception If the placeholder was not found. |
|
477 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
478 | + */ |
|
479 | 479 | public function getPlaceholderByID(int $id) : Mailcode_Parser_Safeguard_Placeholder |
480 | 480 | { |
481 | 481 | $placeholders = $this->getPlaceholders(); |
@@ -498,13 +498,13 @@ discard block |
||
498 | 498 | ); |
499 | 499 | } |
500 | 500 | |
501 | - /** |
|
502 | - * Retrieves a placeholder instance by its replacement text. |
|
503 | - * |
|
504 | - * @param string $string |
|
505 | - * @throws Mailcode_Exception |
|
506 | - * @return Mailcode_Parser_Safeguard_Placeholder |
|
507 | - */ |
|
501 | + /** |
|
502 | + * Retrieves a placeholder instance by its replacement text. |
|
503 | + * |
|
504 | + * @param string $string |
|
505 | + * @throws Mailcode_Exception |
|
506 | + * @return Mailcode_Parser_Safeguard_Placeholder |
|
507 | + */ |
|
508 | 508 | public function getPlaceholderByString(string $string) : Mailcode_Parser_Safeguard_Placeholder |
509 | 509 | { |
510 | 510 | $placeholders = $this->getPlaceholders(); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public function setDelimiter(string $delimiter) : Mailcode_Parser_Safeguard |
136 | 136 | { |
137 | - if(empty($delimiter)) |
|
137 | + if (empty($delimiter)) |
|
138 | 138 | { |
139 | 139 | throw new Mailcode_Exception( |
140 | 140 | 'Empty delimiter', |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $safe = str_replace(array_values($replaces), array_keys($replaces), $this->originalString); |
172 | 172 | |
173 | 173 | // If a formatter has been selected, let it modify the string. |
174 | - if(isset($this->formatter)) |
|
174 | + if (isset($this->formatter)) |
|
175 | 175 | { |
176 | 176 | $safe = $this->formatter->format($safe); |
177 | 177 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | { |
184 | 184 | $class = 'Mailcode\Mailcode_Parser_Safeguard_Formatter_'.$formatterID; |
185 | 185 | |
186 | - if(class_exists($class)) |
|
186 | + if (class_exists($class)) |
|
187 | 187 | { |
188 | 188 | $this->formatter = new $class($this); |
189 | 189 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | $formatter = $this->selectFormatter('SingleLines'); |
211 | 211 | |
212 | - if($formatter instanceof Mailcode_Parser_Safeguard_Formatter_SingleLines) |
|
212 | + if ($formatter instanceof Mailcode_Parser_Safeguard_Formatter_SingleLines) |
|
213 | 213 | { |
214 | 214 | return $formatter; |
215 | 215 | } |
@@ -231,17 +231,17 @@ discard block |
||
231 | 231 | * @param bool $highlighted |
232 | 232 | * @return string[]string |
233 | 233 | */ |
234 | - protected function getReplaces(bool $highlighted=false) : array |
|
234 | + protected function getReplaces(bool $highlighted = false) : array |
|
235 | 235 | { |
236 | 236 | $placeholders = $this->getPlaceholders(); |
237 | 237 | |
238 | 238 | $replaces = array(); |
239 | 239 | |
240 | - foreach($placeholders as $placeholder) |
|
240 | + foreach ($placeholders as $placeholder) |
|
241 | 241 | { |
242 | 242 | $replace = ''; |
243 | 243 | |
244 | - if($highlighted) |
|
244 | + if ($highlighted) |
|
245 | 245 | { |
246 | 246 | $replace = $placeholder->getHighlightedText(); |
247 | 247 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function getPlaceholders() |
267 | 267 | { |
268 | - if(isset($this->placeholders)) |
|
268 | + if (isset($this->placeholders)) |
|
269 | 269 | { |
270 | 270 | return $this->placeholders; |
271 | 271 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | |
275 | 275 | $cmds = $this->getCollection()->getGroupedByHash(); |
276 | 276 | |
277 | - foreach($cmds as $command) |
|
277 | + foreach ($cmds as $command) |
|
278 | 278 | { |
279 | 279 | self::$counter++; |
280 | 280 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | return $this->placeholders; |
289 | 289 | } |
290 | 290 | |
291 | - protected function restore(string $string, bool $partial=false, bool $highlighted=false) : string |
|
291 | + protected function restore(string $string, bool $partial = false, bool $highlighted = false) : string |
|
292 | 292 | { |
293 | 293 | $this->requireValidCollection(); |
294 | 294 | |
@@ -296,9 +296,9 @@ discard block |
||
296 | 296 | |
297 | 297 | $placeholderStrings = array_keys($replaces); |
298 | 298 | |
299 | - foreach($placeholderStrings as $search) |
|
299 | + foreach ($placeholderStrings as $search) |
|
300 | 300 | { |
301 | - if(!$partial && !strstr($string, $search)) |
|
301 | + if (!$partial && !strstr($string, $search)) |
|
302 | 302 | { |
303 | 303 | throw new Mailcode_Exception( |
304 | 304 | 'Command placeholder not found', |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | */ |
401 | 401 | public function getCollection() : Mailcode_Collection |
402 | 402 | { |
403 | - if(isset($this->collection)) |
|
403 | + if (isset($this->collection)) |
|
404 | 404 | { |
405 | 405 | return $this->collection; |
406 | 406 | } |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | */ |
423 | 423 | protected function requireValidCollection() : void |
424 | 424 | { |
425 | - if($this->getCollection()->isValid()) |
|
425 | + if ($this->getCollection()->isValid()) |
|
426 | 426 | { |
427 | 427 | return; |
428 | 428 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function getPlaceholderStrings() : array |
447 | 447 | { |
448 | - if(is_array($this->placeholderStrings)) |
|
448 | + if (is_array($this->placeholderStrings)) |
|
449 | 449 | { |
450 | 450 | return $this->placeholderStrings; |
451 | 451 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | |
455 | 455 | $this->placeholderStrings = array(); |
456 | 456 | |
457 | - foreach($placeholders as $placeholder) |
|
457 | + foreach ($placeholders as $placeholder) |
|
458 | 458 | { |
459 | 459 | $this->placeholderStrings[] = $placeholder->getReplacementText(); |
460 | 460 | } |
@@ -480,9 +480,9 @@ discard block |
||
480 | 480 | { |
481 | 481 | $placeholders = $this->getPlaceholders(); |
482 | 482 | |
483 | - foreach($placeholders as $placeholder) |
|
483 | + foreach ($placeholders as $placeholder) |
|
484 | 484 | { |
485 | - if($placeholder->getID() === $id) |
|
485 | + if ($placeholder->getID() === $id) |
|
486 | 486 | { |
487 | 487 | return $placeholder; |
488 | 488 | } |
@@ -509,9 +509,9 @@ discard block |
||
509 | 509 | { |
510 | 510 | $placeholders = $this->getPlaceholders(); |
511 | 511 | |
512 | - foreach($placeholders as $placeholder) |
|
512 | + foreach ($placeholders as $placeholder) |
|
513 | 513 | { |
514 | - if($placeholder->getReplacementText() === $string) |
|
514 | + if ($placeholder->getReplacementText() === $string) |
|
515 | 515 | { |
516 | 516 | return $placeholder; |
517 | 517 | } |