Passed
Push — feature/optimize ( cf938e...7e8046 )
by Fu
03:43
created

ResponseParse::parseData()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 3
nop 1
dl 0
loc 9
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
4
namespace Modules\Core\Traits\Supports;
5
6
7
use Illuminate\Support\Arr;
8
9
trait ResponseParse
10
{
11
    protected static function parseMeta($data)
12
    {
13
        if ((is_array($data) && Arr::has($data, 'meta'))) {
14
            return Arr::get($data, 'meta');
15
        } else {
16
            return [];
17
        }
18
    }
19
20
    protected static function parseData($data)
21
    {
22
        if (is_array($data) && Arr::has($data, 'data')) {
23
            return Arr::get($data, 'data');
24
        } else {
25
            if (is_string($data) && json_decode($data)) {
26
                return json_decode($data);
27
            } else {
28
                return $data;
29
            }
30
        }
31
    }
32
}