Conditions | 3 |
Paths | 4 |
Total Lines | 32 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function __construct(Tokenizer\Stream $stream, $code = 0, \Throwable $previous = null) |
||
22 | { |
||
23 | $message = 'Unexpected value at line 1, column 1.'; |
||
24 | |||
25 | if ($stream->position < 0) { |
||
26 | $stream->nextToken(); |
||
27 | } |
||
28 | |||
29 | $token = $stream->currentToken(); |
||
30 | |||
31 | if ($token !== null) { |
||
32 | // Get values from all tokens up to here. |
||
33 | $values = array_map( |
||
34 | fn($t) => $t->value, |
||
35 | array_slice($stream->tokens, 0, $stream->position) |
||
36 | ); |
||
37 | |||
38 | // Get coordinates. |
||
39 | [$line, $col] = Tokenizer\Tokenizer::getCoordinates( |
||
40 | implode('', $values), |
||
41 | $token->offset |
||
42 | ); |
||
43 | |||
44 | $message = sprintf( |
||
45 | 'Unexpected %s on line %d, column %d.', |
||
46 | $token->value, |
||
47 | (int)$line, |
||
48 | (int)$col |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | parent::__construct($message, $code, $previous); |
||
53 | } |
||
55 |