Conditions | 3 |
Paths | 3 |
Total Lines | 23 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 3.004 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
49 | 4 | public function capture(Str $string): Map |
|
50 | { |
||
51 | 4 | $matches = []; |
|
52 | 4 | $value = \preg_match($this->pattern, $string->toString(), $matches); |
|
53 | |||
54 | 4 | if ($value === false) { |
|
55 | 1 | throw new RegexException('', \preg_last_error()); |
|
56 | } |
||
57 | |||
58 | /** @var Map<scalar, Str> */ |
||
59 | 3 | $map = Map::of('scalar', Str::class); |
|
60 | |||
61 | 3 | foreach ($matches as $key => $match) { |
|
62 | 3 | $map = ($map)( |
|
63 | 3 | $key, |
|
64 | Str::of( |
||
65 | 3 | (string) $match, |
|
66 | 3 | $string->encoding()->toString() |
|
67 | ) |
||
68 | ); |
||
69 | } |
||
70 | |||
71 | 3 | return $map; |
|
72 | } |
||
79 |