NumberParser::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\id\Helper;
6
7
use byrokrat\id\Exception\InvalidStructureException;
8
9
class NumberParser
10
{
11
    /**
12
     * Parse id using regular expression
13
     *
14
     * @return string[] Array of matches
15
     *
16
     * @throws InvalidStructureException If regular expression does not match
17
     */
18
    public static function parse(string $regexp, string $raw): array
19
    {
20
        if (!preg_match($regexp, $raw, $matches)) {
21
            throw new InvalidStructureException("Unable to parse $raw, invalid structure");
22
        }
23
24
        array_shift($matches);
25
26
        return $matches;
27
    }
28
}
29