NumberParser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 10 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