Completed
Push — master ( 9cb85d...cd38f5 )
by Nico
10:31
created

ParserException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 52
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A unexpectedToken() 0 9 1
A unknownToken() 0 9 1
A incompleteExpression() 0 9 1
A undefinedVariable() 0 9 1
A undefinedMethod() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 * @link        https://github.com/nicoSWD
8
 * @author      Nicolas Oelgart <[email protected]>
9
 */
10
namespace nicoSWD\Rules\Parser\Exception;
11
12
use nicoSWD\Rules\Tokens\BaseToken;
13
14
class ParserException extends \Exception
15
{
16
    public static function unexpectedToken(BaseToken $token): self
17
    {
18
        return new self(sprintf(
19
            'Unexpected "%s" at position %d on line %d',
20
            $token->getValue(),
21
            $token->getPosition(),
22
            $token->getLine()
23
        ));
24
    }
25
26
    public static function unknownToken(BaseToken $token): self
27
    {
28
        return new self(sprintf(
29
            'Unknown token "%s" at position %d on line %d',
30
            $token->getValue(),
31
            $token->getPosition(),
32
            $token->getLine()
33
        ));
34
    }
35
36
    public static function incompleteExpression(BaseToken $token): self
37
    {
38
        return new self(sprintf(
39
            'Incomplete expression for token "%s" at position %d on line %d',
40
            $token->getValue(),
41
            $token->getPosition(),
42
            $token->getLine()
43
        ));
44
    }
45
46
    public static function undefinedVariable(string $name, BaseToken $token): self
47
    {
48
        return new self(sprintf(
49
            'Undefined variable "%s" at position %d on line %d',
50
            $name,
51
            $token->getPosition(),
52
            $token->getLine()
53
        ));
54
    }
55
56
    public static function undefinedMethod(string $name, BaseToken $token): self
57
    {
58
        return new self(sprintf(
59
            'Undefined method "%s" at position %d on line %d',
60
            $name,
61
            $token->getPosition(),
62
            $token->getLine()
63
        ));
64
    }
65
}
66