Total Complexity | 4 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Coverage | 75% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | trait JsonHelperTrait |
||
25 | { |
||
26 | /** |
||
27 | * @param mixed[] $array |
||
28 | * @return stdClass |
||
29 | */ |
||
30 | 5 | public function assocArrToObject(array $array): stdClass |
|
31 | { |
||
32 | try { |
||
33 | 5 | if ($this->isAssoc($array) === false) { |
|
34 | throw new RuntimeException('Array is not associative'); |
||
35 | } |
||
36 | |||
37 | 5 | return json_decode( |
|
38 | 5 | json_encode($array, JSON_THROW_ON_ERROR), |
|
39 | 5 | false, |
|
40 | 5 | 512, |
|
41 | 5 | JSON_THROW_ON_ERROR |
|
42 | ); |
||
43 | } catch (Exception $e) { |
||
44 | throw new ParseErrorException('', 0, $e->getPrevious()); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param mixed[] $data |
||
50 | * @return bool |
||
51 | */ |
||
52 | 5 | public function isAssoc(array &$data): bool |
|
55 | } |
||
56 | } |
||
57 |