Any   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A symbol() 0 3 1
A parse() 0 6 2
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
use Stratadox\Parser\Results\Ok;
9
use function mb_substr;
10
11
/**
12
 * Any Symbol
13
 *
14
 * Matches any single character or symbol.
15
 * Multibyte-safe, fails on empty input.
16
 */
17
final class Any extends Parser
18
{
19
    public static function symbol(): Parser
20
    {
21
        return new self();
22
    }
23
24
    public function parse(string $input): Result
25
    {
26
        if ('' === $input) {
27
            return Error::in('');
28
        }
29
        return Ok::with(mb_substr($input, 0, 1), mb_substr($input, 1));
30
    }
31
}
32