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

ResponseParse   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseData() 0 9 5
A parseMeta() 0 6 3
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
}