| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 80% |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 24 | trait JsonHelperTrait |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @param mixed[] $array |
||
| 28 | * @return mixed |
||
| 29 | */ |
||
| 30 | 8 | public function arrayToObject(array $array) |
|
| 31 | { |
||
| 32 | try { |
||
| 33 | 8 | return json_decode( |
|
| 34 | 8 | json_encode($array, JSON_THROW_ON_ERROR), |
|
| 35 | 8 | false, |
|
| 36 | 8 | 512, |
|
| 37 | 8 | JSON_THROW_ON_ERROR |
|
| 38 | ); |
||
| 39 | } catch (Exception $e) { |
||
| 40 | throw new ParseErrorException('', 0, $e->getPrevious()); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param mixed[] $array |
||
| 46 | * @return stdClass |
||
| 47 | */ |
||
| 48 | 8 | public function assocArrToObject(array $array): stdClass |
|
| 49 | { |
||
| 50 | 8 | if ($this->isAssoc($array) === false) { |
|
| 51 | throw new RuntimeException('Array is not associative'); |
||
| 52 | } |
||
| 53 | |||
| 54 | 8 | return $this->arrayToObject($array); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * method from Kohana |
||
| 59 | * Tests if an array is associative or not. |
||
| 60 | * |
||
| 61 | * @param mixed[] $array |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | 8 | public function isAssoc(array &$array): bool |
|
| 73 | } |
||
| 74 | } |
||
| 75 |