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

SyntaxException::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 6
rs 10
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($x,
29
            JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE |
30
            JSON_INVALID_UTF8_SUBSTITUTE | JSON_THROW_ON_ERROR,
31
        );
32
    }
33
}
34