Error::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 1
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Parser\Results;
4
5
use Stratadox\Parser\Result;
6
use function mb_substr;
7
8
/**
9
 * Error Result
10
 *
11
 * Produced when a parser refuses the input.
12
 */
13
final class Error implements Result
14
{
15
    public function __construct(private string $unparsed) {}
16
17
    public static function in(string $input): Result
18
    {
19
        return new self($input);
20
    }
21
22
    public function data(): string
23
    {
24
        return 'unexpected ' . (empty($this->unparsed) ? 'end' : mb_substr($this->unparsed, 0, 1));
25
    }
26
27
    public function unparsed(): string
28
    {
29
        return $this->unparsed;
30
    }
31
32
    public function ok(): bool
33
    {
34
        return false;
35
    }
36
37
    public function use(): bool
38
    {
39
        return false;
40
    }
41
}
42