AtLeast   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A results() 0 5 2
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\Parser\Helpers;
4
5
use Stratadox\Parser\Parser;
6
use Stratadox\Parser\Parsers\FullyMap;
7
use Stratadox\Parser\Result;
8
use Stratadox\Parser\Results\Error;
9
use function count;
10
11
/**
12
 * AtLeast
13
 *
14
 * Refuses array results with fewer than x entries.
15
 */
16
final class AtLeast
17
{
18
    public static function results(int $n, Parser $parser): Parser
19
    {
20
        return FullyMap::the($parser, fn(Result $result) => count($result->data()) < $n ?
21
            Error::in($result->unparsed()) :
22
            $result
23
        );
24
    }
25
}
26