Completed
Push — master ( 76acb2...4e56bc )
by Nico
02:11
created

ParserException::undefinedFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 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\Rule\Parser\Exception;
11
12
use nicoSWD\Rule\TokenStream\Token\BaseToken;
13
14
class ParserException extends \Exception
15
{
16 20
    public static function unexpectedToken(BaseToken $token): self
17
    {
18 20
        return new self(sprintf(
19 20
            'Unexpected "%s" at position %d on line %d',
20 20
            $token->getValue(),
21 20
            $token->getPosition(),
22 20
            $token->getLine()
23
        ));
24
    }
25
26 6
    public static function unknownToken(BaseToken $token): self
27
    {
28 6
        return new self(sprintf(
29 6
            'Unknown token "%s" at position %d on line %d',
30 6
            $token->getValue(),
31 6
            $token->getPosition(),
32 6
            $token->getLine()
33
        ));
34
    }
35
36 2
    public static function incompleteExpression(BaseToken $token): self
37
    {
38 2
        return new self(sprintf(
39 2
            'Incomplete expression for token "%s" at position %d on line %d',
40 2
            $token->getValue(),
41 2
            $token->getPosition(),
42 2
            $token->getLine()
43
        ));
44
    }
45
46 4
    public static function undefinedVariable(string $name, BaseToken $token): self
47
    {
48 4
        return new self(sprintf(
49 4
            'Undefined variable "%s" at position %d on line %d',
50 4
            $name,
51 4
            $token->getPosition(),
52 4
            $token->getLine()
53
        ));
54
    }
55
56 4
    public static function undefinedMethod(string $name, BaseToken $token): self
57
    {
58 4
        return new self(sprintf(
59 4
            'Undefined method "%s" at position %d on line %d',
60 4
            $name,
61 4
            $token->getPosition(),
62 4
            $token->getLine()
63
        ));
64
    }
65
66 4
    public static function undefinedFunction(string $name): self
67
    {
68 4
        return new self(sprintf(
69 4
            '%s is not defined',
70 4
            $name
71
        ));
72
    }
73
}
74