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

SyntaxException::stringify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
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