wp-user-avatar
/
third-party
/
vendor
/
sabberworm
/
php-css-parser
/
src
/
Parsing
/
UnexpectedTokenException.php
wp-user-avatar
/
third-party
/
vendor
/
sabberworm
/
php-css-parser
/
src
/
Parsing
Last commit date
Anchor.php
5 days ago
OutputException.php
5 days ago
ParserState.php
5 days ago
SourceException.php
5 days ago
UnexpectedEOFException.php
5 days ago
UnexpectedTokenException.php
5 days ago
UnexpectedTokenException.php
30 lines
| 1 | <?php |
| 2 | |
| 3 | declare (strict_types=1); |
| 4 | namespace ProfilePressVendor\Sabberworm\CSS\Parsing; |
| 5 | |
| 6 | /** |
| 7 | * Thrown if the CSS parser encounters a token it did not expect. |
| 8 | */ |
| 9 | class UnexpectedTokenException extends SourceException |
| 10 | { |
| 11 | /** |
| 12 | * @param 'literal'|'identifier'|'count'|'expression'|'search'|'custom' $matchType |
| 13 | * @param int<1, max>|null $lineNumber |
| 14 | */ |
| 15 | public function __construct(string $expected, string $found, string $matchType = 'literal', ?int $lineNumber = null) |
| 16 | { |
| 17 | $message = "Token “{$expected}” ({$matchType}) not found. Got “{$found}”."; |
| 18 | if ($matchType === 'search') { |
| 19 | $message = "Search for “{$expected}” returned no results. Context: “{$found}”."; |
| 20 | } elseif ($matchType === 'count') { |
| 21 | $message = "Next token was expected to have {$expected} chars. Context: “{$found}”."; |
| 22 | } elseif ($matchType === 'identifier') { |
| 23 | $message = "Identifier expected. Got “{$found}”"; |
| 24 | } elseif ($matchType === 'custom') { |
| 25 | $message = \trim("{$expected} {$found}"); |
| 26 | } |
| 27 | parent::__construct($message, $lineNumber); |
| 28 | } |
| 29 | } |
| 30 |