End   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 8 2
A __construct() 0 3 1
A with() 0 3 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