Conditions | 4 |
Paths | 4 |
Total Lines | 18 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | public function get($model, $key, $value, $attributes) |
||
22 | { |
||
23 | if (gettype($value) == 'object') { |
||
24 | preg_match('#\((.*?)\)#', (string)$value, $match); |
||
25 | |||
26 | if (isset($match[1])) { |
||
27 | $match[1] = str_replace('\'', '', $match[1]); |
||
28 | $arr = explode(',', $match[1]); |
||
29 | $values = []; |
||
30 | for ($i = 1; $i < count($arr); $i += 2) { |
||
|
|||
31 | $values[$arr[$i - 1]] = $arr[$i]; |
||
32 | } |
||
33 | |||
34 | return $values; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | return json_decode($value); |
||
39 | } |
||
67 | } |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: