Conditions | 4 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
12 | 14 | static public function parse(string $target): TargetName |
|
|
|||
13 | { |
||
14 | 14 | if (!preg_match('~^' . static::PATTERN . '$~ux', $target, $matches)) { |
|
15 | 1 | preg_match('~' . static::PATTERN . '~ux', $target, $matches); |
|
16 | 1 | $name = $matches[0]; |
|
17 | 1 | throw new InvalidArgumentException( |
|
18 | 1 | "Invalid target name. Did you mean this? '{$name}'." |
|
19 | ); |
||
20 | } |
||
21 | 13 | $iterator = []; |
|
22 | 13 | if ($matches[2]) { |
|
23 | 9 | $iterator = array_map(function ($iterator) { |
|
24 | 9 | if ($iterator === '') return null; |
|
25 | 2 | return (int) $iterator; |
|
26 | 9 | }, explode('][', rtrim(ltrim($matches[2], '['), ']'))); |
|
27 | } |
||
28 | 13 | return new static($matches[1], $iterator, !!($matches[3] ?? null)); |
|
29 | } |
||
30 | |||
71 |