Passed
Pull Request — master (#1)
by
unknown
02:19
created

SyntaxException   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A stringify() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\FormulaTools\V2\Exceptions;
6
7
class SyntaxException extends \ErrorException
8
{
9
    /** @readonly */
10
    public ?int $position;
11
12
    public function __construct(string $msg, ?int $position)
13
    {
14
        $this->position = $position;
15
        if ($position !== null) {
16
            $position++;
17
            $msg = "Token #$position: $msg";
18
        }
19
        parent::__construct($msg);
20
    }
21
22
    /**
23
     * @param mixed $x
24
     * @return string
25
     */
26
    protected function stringify($x): string
27
    {
28
        return json_encode(
29
            $x,
30
            JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE |
31
            JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR,
32
        );
33
    }
34
}
35