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