End::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Parser\Parsers;
4
5
use Stratadox\Parser\Parser;
6
use Stratadox\Parser\Result;
7
use Stratadox\Parser\Results\Error;
8
9
/**
10
 * End
11
 *
12
 * Returns an error result if there is unparsed content remaining after parsing.
13
 */
14
final class End extends Parser
15
{
16
    public function __construct(
17
        private Parser $parser,
18
    ) {}
19
20
    public static function with(Parser $parser): Parser
21
    {
22
        return new self($parser);
23
    }
24
25
    public function parse(string $input): Result
26
    {
27
        $result = $this->parser->parse($input);
28
29
        if ('' === $result->unparsed()) {
30
            return $result;
31
        }
32
        return Error::in($result->unparsed());
33
    }
34
}
35