Passed
Branch feature/first-release (5d23f8)
by Andrea Marco
10:49
created

SyntaxException::setPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Exceptions;
4
5
use Exception;
6
7
/**
8
 * The exception thrown when the JSON syntax is not valid.
9
 *
10
 */
11
final class SyntaxException extends Exception implements JsonParserException
12
{
13
    /**
14
     * The error position.
15
     *
16
     * @var int|null
17
     */
18
    public ?int $position = null;
19
20
    /**
21
     * Instantiate the class
22
     *
23
     * @param string $value
24
     */
25 11
    public function __construct(public string $value)
26
    {
27 11
        parent::__construct("Syntax error: unexpected '$value'");
28
    }
29
30
    /**
31
     * Set the error position
32
     *
33
     * @param int $position
34
     * @return self
35
     */
36 11
    public function setPosition(int $position): self
37
    {
38 11
        $this->position = $position;
39 11
        $this->message .= " at position {$position}";
40
41 11
        return $this;
42
    }
43
}
44