ParserException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 52
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A squareBracketMismatch() 0 3 1
A placeholderExceeded() 0 3 1
A duplicatePlaceholder() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Lead\Router\Exception;
5
6
use RuntimeException;
7
8
/**
9
 * ParserException
10
 */
11
class ParserException extends RuntimeException
12
{
13
    const SQUARE_BRACKET_MISMATCH = 1;
14
15
    const DUPLICATE_PLACEHOLDER = 2;
16
17
    const PLACEHOLDER_EXCEEDED = 3;
18
19
    /**
20
     * The missing placeholder name.
21
     *
22
     * @var string
23
     */
24
    public $placeholder = '';
25
26
    /**
27
     * The error code.
28
     *
29
     * @var integer
30
     */
31
    protected $code = 500;
32
33
    /**
34
     * Creates a square bracket mismatch exception.
35
     *
36
     * @return $this
37
     */
38
    public static function squareBracketMismatch()
39
    {
40 1
        return new static("Number of opening '[' and closing ']' does not match.", static::SQUARE_BRACKET_MISMATCH);
41
    }
42
43
    /**
44
     * Creates a duplicate placeholder exception.
45
     *
46
     * @return $this
47
     */
48
    public static function duplicatePlaceholder($placeholder = '')
49
    {
50 2
        $exception = new static("Cannot use the same placeholder `{$placeholder}` twice.", static::DUPLICATE_PLACEHOLDER);
51 2
        $exception->placeholder = $placeholder;
52 2
        return $exception;
53
    }
54
55
    /**
56
     * Creates a placeholder exceeded exception.
57
     *
58
     * @return $this
59
     */
60
    public static function placeholderExceeded()
61
    {
62 1
        return new static("Only a single placeholder is allowed in repeatable segments.", static::PLACEHOLDER_EXCEEDED);
63
    }
64
}
65