← All changes
|
back/Libraries/Sabberworm/CSS/src/Parsing/UnexpectedTokenException.php
+31
-0
10.2.0
→
11.1.0
View file →
| @@ -1,0 +1,31 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace AcyMailing\Libraries\Sabberworm\CSS\Parsing; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Thrown if the CSS parser encounters a token it did not expect. | |
| 9 | + */ | |
| 10 | +class UnexpectedTokenException extends SourceException | |
| 11 | +{ | |
| 12 | + /** | |
| 13 | + * @param 'literal'|'identifier'|'count'|'expression'|'search'|'custom' $matchType | |
| 14 | + * @param int<1, max>|null $lineNumber | |
| 15 | + */ | |
| 16 | + public function __construct(string $expected, string $found, string $matchType = 'literal', ?int $lineNumber = null) | |
| 17 | + { | |
| 18 | + $message = "Token “{$expected}” ({$matchType}) not found. Got “{$found}”."; | |
| 19 | + if ($matchType === 'search') { | |
| 20 | + $message = "Search for “{$expected}” returned no results. Context: “{$found}”."; | |
| 21 | + } elseif ($matchType === 'count') { | |
| 22 | + $message = "Next token was expected to have {$expected} chars. Context: “{$found}”."; | |
| 23 | + } elseif ($matchType === 'identifier') { | |
| 24 | + $message = "Identifier expected. Got “{$found}”"; | |
| 25 | + } elseif ($matchType === 'custom') { | |
| 26 | + $message = \trim("$expected $found"); | |
| 27 | + } | |
| 28 | + | |
| 29 | + parent::__construct($message, $lineNumber); | |
| 30 | + } | |
| 31 | +} | |