Completed
Pull Request — master (#21)
by Hannes
09:11
created

NumberParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 8 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
        return $matches;
25
    }
26
}
27