Completed
Pull Request — master (#47)
by Jasper
11:54
created

Meta::__isset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Swis\JsonApi\Client;
4
5
use ArrayAccess;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Contracts\Support\Jsonable;
8
use JsonSerializable;
9
10
class Meta implements ArrayAccess, Arrayable, Jsonable, JsonSerializable
11
{
12
    /**
13
     * @var array
14
     */
15
    protected $data = [];
16
17
    /**
18
     * @param array $data
19
     */
20
    public function __construct(array $data)
21
    {
22
        $this->data = $data;
23
    }
24
25
    /**
26
     * @param $key
27
     *
28
     * @return bool
29
     */
30
    public function __isset($key)
31
    {
32
        return $this->offsetExists($key);
33
    }
34
35
    /**
36
     * @param $key
37
     *
38
     * @return mixed
39
     */
40
    public function __get($key)
41
    {
42
        return $this->offsetGet($key);
43
    }
44
45
    /**
46
     * @param $key
47
     */
48
    public function __unset($key)
49
    {
50
        $this->offsetUnset($key);
51
    }
52
53
    /**
54
     * @param $key
55
     * @param $value
56
     */
57
    public function __set($key, $value)
58
    {
59
        $this->offsetSet($key, $value);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     *
65
     * @param mixed $offset
66
     *
67
     * @return bool
68
     */
69
    public function offsetExists($offset)
70
    {
71
        return isset($this->data[$offset]);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     *
77
     * @param mixed $offset
78
     *
79
     * @return mixed
80
     */
81
    public function offsetGet($offset)
82
    {
83
        return $this->data[$offset] ?? null;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     *
89
     * @param mixed $offset
90
     * @param mixed $value
91
     */
92
    public function offsetSet($offset, $value)
93
    {
94
        $this->data[$offset] = $value;
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     *
100
     * @param mixed $offset
101
     */
102
    public function offsetUnset($offset)
103
    {
104
        unset($this->data[$offset]);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     *
110
     * @return array
111
     */
112
    public function toArray()
113
    {
114
        return $this->data;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     *
120
     * @param int $options
121
     *
122
     * @return false|string
123
     */
124
    public function toJson($options = 0)
125
    {
126
        return json_encode($this->jsonSerialize(), $options);
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     *
132
     * @return array|mixed
133
     */
134
    public function jsonSerialize()
135
    {
136
        return $this->toArray();
137
    }
138
}
139