ParseException::unexpected()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * This file is part of PHP-Yacc package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace PhpYacc\Exception;
11
12
use PhpYacc\Yacc\Token;
13
14
/**
15
 * Class ParseException.
16
 */
17
class ParseException extends PhpYaccException
18
{
19
    /**
20
     * @param Token $token
21
     * @param $expecting
22
     *
23
     * @return ParseException
24
     */
25
    public static function unexpected(Token $token, $expecting): self
26
    {
27
        $fileName = $token->getFilename();
28
        $line = $token->getLine();
29
30
        return new self(\sprintf(
31
            'Unexpected %s, expecting %s at %s:%d',
32
            Token::decode($token->getType()), Token::decode($expecting), $fileName, $line
33
        ));
34
    }
35
}
36