Error   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 6
c 1
b 0
f 0
dl 0
loc 27
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A unparsed() 0 3 1
A ok() 0 3 1
A in() 0 3 1
A __construct() 0 1 1
A data() 0 3 2
A use() 0 3 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