Completed
Pull Request — master (#4)
by ARCANEDEV
05:31
created

AbstractResponse   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 79
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2
ccs 9
cts 9
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRaw() 0 4 1
A get() 0 4 1
A isOk() 0 4 1
1
<?php namespace Arcanedev\GeoLocation\Google;
2
3
use Arcanedev\GeoLocation\Traits\CanBeJsonable;
4
use Illuminate\Contracts\Support\Arrayable;
5
use Illuminate\Contracts\Support\Jsonable;
6
use Illuminate\Support\Arr;
7
use JsonSerializable;
8
9
/**
10
 * Class     AbstractResponse
11
 *
12
 * @package  Arcanedev\GeoLocation\Google
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
abstract class AbstractResponse implements Arrayable, Jsonable, JsonSerializable
16
{
17
    /* -----------------------------------------------------------------
18
     |  Traits
19
     | -----------------------------------------------------------------
20
     */
21
22
    use CanBeJsonable;
23
24
    /* -----------------------------------------------------------------
25
     |  Properties
26
     | -----------------------------------------------------------------
27
     */
28
29
    /**
30
     * The response's data.
31
     *
32
     * @var  array
33
     */
34
    protected $data = [];
35
36
    /* -----------------------------------------------------------------
37
     |  Constructor
38
     | -----------------------------------------------------------------
39
     */
40
41
    /**
42
     * AbstractResponse constructor.
43
     *
44
     * @param  array  $data
45
     */
46 102
    public function __construct(array $data = [])
47
    {
48 102
        $this->data = $data;
49 102
    }
50
51
    /* -----------------------------------------------------------------
52
     |  Getters & Setters
53
     | -----------------------------------------------------------------
54
     */
55
56
    /**
57
     * Get the raw response.
58
     *
59
     * @return array
60
     */
61 96
    public function getRaw()
62
    {
63 96
        return $this->data;
64
    }
65
66
    /* -----------------------------------------------------------------
67
     |  Main Methods
68
     | -----------------------------------------------------------------
69
     */
70
71
    /**
72
     * Get a data with a given key.
73
     *
74
     * @param  string      $key
75
     * @param  mixed|null  $default
76
     *
77
     * @return mixed
78
     */
79 90
    public function get($key, $default = null)
80
    {
81 90
        return Arr::get($this->getRaw(), $key, $default);
82
    }
83
84
    /**
85
     * Check if the response's status is OK.
86
     *
87
     * @return bool
88
     */
89 33
    public function isOk()
90
    {
91 33
        return $this->get('status') === 'OK';
92
    }
93
}
94