GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HasDataTrait   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 307
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 307
ccs 62
cts 62
cp 1
rs 10
c 0
b 0
f 0
wmc 26

25 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A setReference() 0 3 1
A search() 0 3 1
A flatten() 0 3 1
A isEmpty() 0 3 1
A get() 0 3 1
A set() 0 3 1
A toJson() 0 3 1
A clear() 0 3 1
A offsetSet() 0 4 1
A __set() 0 3 1
A __get() 0 7 2
A __isset() 0 3 1
A __unset() 0 3 1
A add() 0 3 1
A dot() 0 3 1
A count() 0 4 1
A all() 0 3 1
A has() 0 3 1
A offsetUnset() 0 4 1
A getIterator() 0 4 1
A delete() 0 3 1
A offsetGet() 0 4 1
A jsonSerialize() 0 4 1
A offsetExists() 0 4 1
1
<?php
2
3
namespace AlibabaCloud\Client\Traits;
4
5
use Adbar\Dot;
6
use ArrayIterator;
7
use JmesPath\Env as JmesPath;
8
use AlibabaCloud\Client\Result\Result;
9
10
/**
11
 * Trait HasDataTrait
12
 *
13
 * @package   AlibabaCloud\Client\Traits
14
 * @mixin     Result
15
 */
16
trait HasDataTrait
17
{
18
19
    /**
20
     * Instance of the Dot.
21
     *
22
     * @var Dot
23
     */
24
    protected $dot;
25
26
    /**
27
     * @param string $expression
28
     *
29
     * @return mixed|null
30
     */
31 4
    public function search($expression)
32
    {
33 4
        return JmesPath::search($expression, $this->dot->all());
34
    }
35
36
    /**
37
     * Delete the contents of a given key or keys
38
     *
39
     * @param array|int|string|null $keys
40
     */
41 2
    public function clear($keys = null)
42
    {
43 2
        $this->dot->clear($keys);
44 2
    }
45
46
    /**
47
     * Flatten an array with the given character as a key delimiter
48
     *
49
     * @param string     $delimiter
50
     * @param array|null $items
51
     * @param string     $prepend
52
     *
53
     * @return array
54
     */
55 1
    public function flatten($delimiter = '.', $items = null, $prepend = '')
56
    {
57 1
        return $this->dot->flatten($delimiter, $items, $prepend);
58
    }
59
60
    /**
61
     * Return the value of a given key
62
     *
63
     * @param int|string|null $key
64
     * @param mixed           $default
65
     *
66
     * @return mixed
67
     */
68 2
    public function get($key = null, $default = null)
69
    {
70 2
        return $this->dot->get($key, $default);
71
    }
72
73
    /**
74
     * Set a given key / value pair or pairs
75
     *
76
     * @param array|int|string $keys
77
     * @param mixed            $value
78
     */
79 7
    public function set($keys, $value = null)
80
    {
81 7
        $this->dot->set($keys, $value);
82 7
    }
83
84
    /**
85
     * Check if a given key or keys are empty
86
     *
87
     * @param array|int|string|null $keys
88
     *
89
     * @return bool
90
     */
91 1
    public function isEmpty($keys = null)
92
    {
93 1
        return $this->dot->isEmpty($keys);
94
    }
95
96
    /**
97
     * Replace all items with a given array as a reference
98
     *
99
     * @param array $items
100
     */
101 1
    public function setReference(array &$items)
102
    {
103 1
        $this->dot->setReference($items);
104 1
    }
105
106
    /**
107
     * Return the value of a given key or all the values as JSON
108
     *
109
     * @param mixed $key
110
     * @param int   $options
111
     *
112
     * @return string
113
     */
114 1
    public function toJson($key = null, $options = 0)
115
    {
116 1
        return $this->dot->toJson($key, $options);
117
    }
118
119
    /**
120
     * @return array
121
     */
122 4
    public function toArray()
123
    {
124 4
        return $this->dot->all();
125
    }
126
127
    /**
128
     * Check if a given key exists
129
     *
130
     * @param int|string $key
131
     *
132
     * @return bool
133
     */
134 37
    #[\ReturnTypeWillChange]
135
    public function offsetExists($key)
136 37
    {
137
        return $this->dot->has($key);
138
    }
139
140
    /**
141
     * Return the value of a given key
142
     *
143
     * @param int|string $key
144
     *
145
     * @return mixed
146 45
     */
147
    #[\ReturnTypeWillChange]
148 45
    public function offsetGet($key)
149
    {
150
        return $this->dot->offsetGet($key);
151
    }
152
153
    /**
154
     * Set a given value to the given key
155
     *
156
     * @param int|string|null $key
157 5
     * @param mixed           $value
158
     */
159 5
    #[\ReturnTypeWillChange]
160 5
    public function offsetSet($key, $value)
161
    {
162
        $this->dot->offsetSet($key, $value);
163
    }
164
165
    /**
166
     * Delete the given key
167 1
     *
168
     * @param int|string $key
169 1
     */
170 1
    #[\ReturnTypeWillChange]
171
    public function offsetUnset($key)
172
    {
173
        $this->delete($key);
174
    }
175
176
    /**
177 3
     * Delete the given key or keys
178
     *
179 3
     * @param array|int|string $keys
180 3
     */
181
    public function delete($keys)
182
    {
183
        $this->dot->delete($keys);
184
    }
185
186
    /*
187
     * --------------------------------------------------------------
188
     * ArrayAccess interface
189
     * --------------------------------------------------------------
190
     */
191
192
    /**
193
     * Return the number of items in a given key
194
     *
195 1
     * @param int|string|null $key
196
     *
197 1
     * @return int
198
     */
199
    #[\ReturnTypeWillChange]
200
    public function count($key = null)
201
    {
202
        return $this->dot->count($key);
203
    }
204
205 1
    /**
206
     * Get an iterator for the stored items
207 1
     *
208
     * @return ArrayIterator
209
     */
210
    #[\ReturnTypeWillChange]
211
    public function getIterator()
212
    {
213
        return $this->dot->getIterator();
214
    }
215 1
216
    /**
217 1
     * Return items for JSON serialization
218
     *
219
     * @return array
220
     */
221
    #[\ReturnTypeWillChange]
222
    public function jsonSerialize()
223
    {
224
        return $this->dot->jsonSerialize();
225 5
    }
226
227 5
    /**
228 1
     * @param string $name
229
     *
230
     * @return mixed|null
231 5
     */
232
    public function __get($name)
233
    {
234
        if (!isset($this->all()[$name])) {
235
            return null;
236
        }
237
238
        return \json_decode(\json_encode($this->all()))->$name;
239
    }
240
241
    /*
242
     * --------------------------------------------------------------
243
     * Countable interface
244
     * --------------------------------------------------------------
245 10
     */
246
247 10
    /**
248
     * Return all the stored items
249
     *
250
     * @return array
251
     */
252
    public function all()
253
    {
254 3
        return $this->dot->all();
255
    }
256 3
257 3
    /**
258
     * @param string $name
259
     * @param mixed  $value
260
     */
261
    public function __set($name, $value)
262
    {
263
        $this->add($name, $value);
264
    }
265
266 9
    /**
267
     * Set a given key / value pair or pairs
268 9
     * if the key doesn't exist already
269 9
     *
270
     * @param array|int|string $keys
271
     * @param mixed            $value
272
     */
273
    public function add($keys, $value = null)
274
    {
275
        $this->dot->add($keys, $value);
276
    }
277
278
279
    /*
280
     * --------------------------------------------------------------
281
     * ObjectAccess
282
     * --------------------------------------------------------------
283 4
     */
284
285 4
    /**
286
     * @param string $name
287
     *
288
     * @return bool
289
     */
290
    public function __isset($name)
291
    {
292
        return $this->has($name);
293
    }
294
295 5
    /**
296
     * Check if a given key or keys exists
297 5
     *
298
     * @param array|int|string $keys
299
     *
300
     * @return bool
301
     */
302
    public function has($keys)
303
    {
304
        return $this->dot->has($keys);
305 1
    }
306
307 1
    /**
308 1
     * @param $name
309
     *
310
     * @return void
311
     */
312
    public function __unset($name)
313 99
    {
314
        $this->delete($name);
315 99
    }
316 99
317
    /**
318
     * @param array $data
319
     */
320
    protected function dot(array $data = [])
321
    {
322
        $this->dot = new Dot($data);
323
    }
324
}
325