Conditions | 4 |
Paths | 4 |
Total Lines | 24 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
25 | public static function stringToArray(string $string = null, string $valueDelimiter = ':', string $itemDelimiter = ',') |
||
26 | { |
||
27 | if(is_null($string)) { |
||
28 | return []; |
||
29 | } |
||
30 | |||
31 | $values = []; |
||
32 | $items = preg_split('/' . preg_quote($itemDelimiter) . '/', $string, -1, PREG_SPLIT_NO_EMPTY); |
||
33 | |||
34 | foreach ($items as $index => $item) { |
||
35 | $item = explode($valueDelimiter, $item); |
||
36 | |||
37 | $key = Arr::get($item, 0); |
||
38 | $value = Arr::get($item, 1); |
||
39 | |||
40 | if(is_null($value)) { |
||
41 | $value = $key; |
||
42 | $key = $index; |
||
43 | } |
||
44 | |||
45 | $values[trim($key)] = trim($value); |
||
|
|||
46 | } |
||
47 | |||
48 | return $values; |
||
49 | } |
||
50 | } |