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.
Passed
Pull Request — master (#231)
by Yong
09:44 queued 05:23
created

HasDataTrait   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 300
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 300
ccs 61
cts 61
cp 1
rs 10
wmc 26

25 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A toArray() 0 3 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 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 all() 0 3 1
A set() 0 3 1
A has() 0 3 1
A toJson() 0 3 1
A offsetUnset() 0 3 1
A getIterator() 0 3 1
A delete() 0 3 1
A offsetGet() 0 3 1
A jsonSerialize() 0 3 1
A offsetExists() 0 3 1
A clear() 0 3 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
    public function offsetExists($key)
135
    {
136 37
        return $this->dot->has($key);
137
    }
138
139
    /**
140
     * Return the value of a given key
141
     *
142
     * @param int|string $key
143
     *
144
     * @return mixed
145
     */
146 45
    public function offsetGet($key)
147
    {
148 45
        return $this->dot->offsetGet($key);
149
    }
150
151
    /**
152
     * Set a given value to the given key
153
     *
154
     * @param int|string|null $key
155
     * @param mixed           $value
156
     */
157 5
    public function offsetSet($key, $value)
158
    {
159 5
        $this->dot->offsetSet($key, $value);
160 5
    }
161
162
    /**
163
     * Delete the given key
164
     *
165
     * @param int|string $key
166
     */
167 1
    public function offsetUnset($key)
168
    {
169 1
        $this->delete($key);
170 1
    }
171
172
    /**
173
     * Delete the given key or keys
174
     *
175
     * @param array|int|string $keys
176
     */
177 3
    public function delete($keys)
178
    {
179 3
        $this->dot->delete($keys);
180 3
    }
181
182
    /*
183
     * --------------------------------------------------------------
184
     * ArrayAccess interface
185
     * --------------------------------------------------------------
186
     */
187
188
    /**
189
     * Return the number of items in a given key
190
     *
191
     * @param int|string|null $key
192
     *
193
     * @return int
194
     */
195 1
    public function count($key = null)
196
    {
197 1
        return $this->dot->count($key);
198
    }
199
200
    /**
201
     * Get an iterator for the stored items
202
     *
203
     * @return ArrayIterator
204
     */
205 1
    public function getIterator()
206
    {
207 1
        return $this->dot->getIterator();
208
    }
209
210
    /**
211
     * Return items for JSON serialization
212
     *
213
     * @return array
214
     */
215 1
    public function jsonSerialize()
216
    {
217 1
        return $this->dot->jsonSerialize();
218
    }
219
220
    /**
221
     * @param string $name
222
     *
223
     * @return mixed|null
224
     */
225 5
    public function __get($name)
226
    {
227 5
        if (!isset($this->all()[$name])) {
228 1
            return null;
229
        }
230
231 5
        return \json_decode(\json_encode($this->all()))->$name;
232
    }
233
234
    /*
235
     * --------------------------------------------------------------
236
     * Countable interface
237
     * --------------------------------------------------------------
238
     */
239
240
    /**
241
     * Return all the stored items
242
     *
243
     * @return array
244
     */
245 10
    public function all()
246
    {
247 10
        return $this->dot->all();
248
    }
249
250
    /**
251
     * @param string $name
252
     * @param mixed  $value
253
     */
254 3
    public function __set($name, $value)
255
    {
256 3
        $this->add($name, $value);
257 3
    }
258
259
    /**
260
     * Set a given key / value pair or pairs
261
     * if the key doesn't exist already
262
     *
263
     * @param array|int|string $keys
264
     * @param mixed            $value
265
     */
266 9
    public function add($keys, $value = null)
267
    {
268 9
        $this->dot->add($keys, $value);
269 9
    }
270
271
272
    /*
273
     * --------------------------------------------------------------
274
     * ObjectAccess
275
     * --------------------------------------------------------------
276
     */
277
278
    /**
279
     * @param string $name
280
     *
281
     * @return bool
282
     */
283 4
    public function __isset($name)
284
    {
285 4
        return $this->has($name);
286
    }
287
288
    /**
289
     * Check if a given key or keys exists
290
     *
291
     * @param array|int|string $keys
292
     *
293
     * @return bool
294
     */
295 5
    public function has($keys)
296
    {
297 5
        return $this->dot->has($keys);
298
    }
299
300
    /**
301
     * @param $name
302
     *
303
     * @return void
304
     */
305 1
    public function __unset($name)
306
    {
307 1
        $this->delete($name);
308 1
    }
309
310
    /**
311
     * @param array $data
312
     */
313 99
    protected function dot(array $data = [])
314
    {
315 99
        $this->dot = new Dot($data);
316 99
    }
317
}
318