Passed
Push — master ( e32e27...b9c4c4 )
by Nico
01:27
created

ParserException   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 45
ccs 18
cts 18
cp 1
rs 10
wmc 9

9 Methods

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