Conditions | 3 |
Paths | 3 |
Total Lines | 18 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
20 | 13 | protected function splitValue(string $value): array |
|
21 | { |
||
22 | 13 | $regexpKey = '(?:\'(?:[^\']++|\\\\.)*\'|"(?:[^"]++|\\\\.)*"|[^,\'"\=]++|[\'"])*'; |
|
23 | 13 | $regexpValue = '\'(?:[^\']++|\\\\.)*\'|(?:"(?:[^"]++|\\\\.)*"|[^,\'"]+|[\'"])*'; |
|
24 | 13 | $regexp = '/(?<=^|,)(?:(?<key>' . $regexpKey . ')\s*=\s*)?(?<value>' . $regexpValue. ')\s*/'; |
|
25 | |||
26 | 13 | preg_match_all($regexp, $value, $matches, PREG_PATTERN_ORDER); // regex can't fail |
|
27 | |||
28 | 13 | $keys = preg_replace('/^\s*(["\']?)(.*?)\1\s*$/', '$2', $matches['key']); |
|
29 | |||
30 | 13 | foreach ($keys as $pos => $key) { |
|
31 | 13 | if ($key === '') { |
|
32 | 2 | $item = trim($matches['value'][$pos]); |
|
33 | 2 | throw new PhpdocException("Failed to parse '@{$this->name} {$value}': no key for value '$item'"); |
|
34 | } |
||
35 | } |
||
36 | |||
37 | 11 | return array_combine($keys, $matches['value']); |
|
38 | } |
||
40 |