| Total Complexity | 11 | 
| Total Lines | 75 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 8 | abstract class JsonAbstract  | 
            ||
| 9 | { | 
            ||
| 10 | /**  | 
            ||
| 11 | * @param array $jsonApiArr  | 
            ||
| 12 | *  | 
            ||
| 13 | * @return array  | 
            ||
| 14 | */  | 
            ||
| 15 | public static function getAttributes(array $jsonApiArr) : array  | 
            ||
| 16 |     { | 
            ||
| 17 | return empty($jsonApiArr[ApiInterface::RAML_DATA][ApiInterface::RAML_ATTRS]) ? [] : $jsonApiArr[ApiInterface::RAML_DATA][ApiInterface::RAML_ATTRS];  | 
            ||
| 18 | }  | 
            ||
| 19 | |||
| 20 | /**  | 
            ||
| 21 | * Returns an array of bulk attributes for each element  | 
            ||
| 22 | *  | 
            ||
| 23 | * @param array $jsonApiArr  | 
            ||
| 24 | * @return array  | 
            ||
| 25 | */  | 
            ||
| 26 | public static function getBulkAttributes(array $jsonApiArr) : array  | 
            ||
| 27 |     { | 
            ||
| 28 | return empty($jsonApiArr[ApiInterface::RAML_DATA]) ? [] : $jsonApiArr[ApiInterface::RAML_DATA];  | 
            ||
| 29 | }  | 
            ||
| 30 | |||
| 31 | /**  | 
            ||
| 32 | * @param array $jsonApiArr  | 
            ||
| 33 | *  | 
            ||
| 34 | * @return array  | 
            ||
| 35 | */  | 
            ||
| 36 | public static function getRelationships(array $jsonApiArr) : array  | 
            ||
| 37 |     { | 
            ||
| 38 | return empty($jsonApiArr[ApiInterface::RAML_DATA][ApiInterface::RAML_RELATIONSHIPS]) ? [] : $jsonApiArr[ApiInterface::RAML_DATA][ApiInterface::RAML_RELATIONSHIPS];  | 
            ||
| 39 | }  | 
            ||
| 40 | |||
| 41 | /**  | 
            ||
| 42 | * @param array $jsonApiArr  | 
            ||
| 43 | *  | 
            ||
| 44 | * @return array  | 
            ||
| 45 | */  | 
            ||
| 46 | public static function getData(array $jsonApiArr) : array  | 
            ||
| 47 |     { | 
            ||
| 48 | return empty($jsonApiArr[ApiInterface::RAML_DATA]) ? [] : $jsonApiArr[ApiInterface::RAML_DATA];  | 
            ||
| 49 | }  | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * Encoder array -> json  | 
            ||
| 53 | *  | 
            ||
| 54 | * @param array $array  | 
            ||
| 55 | * @param int $opts  | 
            ||
| 56 | * @return string  | 
            ||
| 57 | */  | 
            ||
| 58 | public static function encode(array $array, int $opts = 0): string  | 
            ||
| 59 |     { | 
            ||
| 60 | return json_encode($array, $opts);  | 
            ||
| 61 | }  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * Decoder json -> array  | 
            ||
| 65 | *  | 
            ||
| 66 | * @param mixed $json  | 
            ||
| 67 | * @return mixed  | 
            ||
| 68 | */  | 
            ||
| 69 | public static function decode(string $json): array  | 
            ||
| 70 |     { | 
            ||
| 71 | return json_decode($json, true);  | 
            ||
| 72 | }  | 
            ||
| 73 | |||
| 74 | /**  | 
            ||
| 75 | * This method is wrapper over decode to let polymorphism between raml/json parsers  | 
            ||
| 76 | *  | 
            ||
| 77 | * @param string $json  | 
            ||
| 78 | * @return array  | 
            ||
| 79 | */  | 
            ||
| 80 | public static function parse(string $json): array  | 
            ||
| 83 | }  | 
            ||
| 84 | }  |