Conditions | 3 |
Paths | 3 |
Total Lines | 22 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
44 | 8 | public function capture(Str $string): MapInterface |
|
45 | { |
||
46 | 8 | $matches = []; |
|
47 | 8 | $value = \preg_match($this->pattern, (string) $string, $matches); |
|
48 | |||
49 | 8 | if ($value === false) { |
|
50 | 2 | throw new RegexException('', \preg_last_error()); |
|
51 | } |
||
52 | |||
53 | 6 | $map = new Map('scalar', Str::class); |
|
54 | |||
55 | 6 | foreach ($matches as $key => $match) { |
|
56 | 6 | $map = $map->put( |
|
57 | 6 | $key, |
|
58 | 6 | new Str( |
|
59 | 6 | (string) $match, |
|
60 | 6 | (string) $string->encoding() |
|
61 | ) |
||
62 | ); |
||
63 | } |
||
64 | |||
65 | 6 | return $map; |
|
66 | } |
||
73 |