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.

Environment::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Containers;
15
16
// ------------------------------------------------------------------------
17
18
use Psr\Container\ContainerExceptionInterface;
19
use Psr\Container\ContainerInterface;
20
use O2System\Psr\NotFoundExceptionInterface;
0 ignored issues
show
Bug introduced by
The type O2System\Psr\NotFoundExceptionInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Traversable;
22
23
/**
24
 * Class Environment
25
 *
26
 * @package O2System\Framework\Container
27
 */
28
class Environment implements
29
    \ArrayAccess,
30
    \IteratorAggregate,
31
    \Countable,
32
    \Serializable,
33
    \JsonSerializable,
34
    ContainerInterface
35
{
36
    /**
37
     * Environment::getIterator
38
     *
39
     * Retrieve an external iterator
40
     *
41
     * @link  http://php.net/manual/en/iteratoraggregate.getiterator.php
42
     * @return Traversable An instance of an object implementing <b>Iterator</b> or
43
     *        <b>Traversable</b>
44
     * @since 5.0.0
45
     */
46
    public function getIterator()
47
    {
48
        return new \ArrayIterator($_ENV);
49
    }
50
51
    // ------------------------------------------------------------------------
52
53
    /**
54
     * Environment::exists
55
     *
56
     * Checks if the data exists on the storage.
57
     * An alias of Environment::__isset method.
58
     *
59
     * @param string $offset The object offset key.
60
     *
61
     * @return bool Returns TRUE on success or FALSE on failure.
62
     */
63
    public function exists($offset)
64
    {
65
        return $this->__isset($offset);
66
    }
67
68
    // ------------------------------------------------------------------------
69
70
    /**
71
     * Environment::__isset
72
     *
73
     * Implementing magic method __isset to simplify when checks if offset exists on PHP native session variable,
74
     * just simply calling isset( $globals[ 'offset' ] ).
75
     *
76
     * @param mixed $offset PHP native GLOBALS offset.
77
     *
78
     * @return bool
79
     */
80
    public function __isset($offset)
81
    {
82
        return $this->offsetExists($offset);
83
    }
84
85
    // ------------------------------------------------------------------------
86
87
    /**
88
     * Environment::offsetExists
89
     *
90
     * Whether a offset exists
91
     *
92
     * @link  http://php.net/manual/en/arrayaccess.offsetexists.php
93
     *
94
     * @param mixed $offset <p>
95
     *                      An offset to check for.
96
     *                      </p>
97
     *
98
     * @return boolean true on success or false on failure.
99
     * </p>
100
     * <p>
101
     * The return value will be casted to boolean if non-boolean was returned.
102
     * @since 5.0.0
103
     */
104
    public function offsetExists($offset)
105
    {
106
        return isset($_ENV[ $offset ]);
107
    }
108
109
    // ------------------------------------------------------------------------
110
111
    /**
112
     * Environment::::__get
113
     *
114
     * Implementing magic method __get to simplify gets PHP native session variable by requested offset,
115
     * just simply calling isset( $session[ 'offset' ] ).
116
     *
117
     * @param $offset
118
     *
119
     * @return mixed
120
     */
121
    public function &__get($offset)
122
    {
123
        return $_ENV[ $offset ];
124
    }
125
126
    // ------------------------------------------------------------------------
127
128
    /**
129
     * Environment::__set
130
     *
131
     * Implementing magic method __set to simplify set PHP native GLOBALS variable,
132
     * just simply calling $globals->offset = 'foo'.
133
     *
134
     * @param mixed $offset PHP native GLOBALS offset.
135
     * @param mixed $value  PHP native GLOBALS offset value to set.
136
     */
137
    public function __set($offset, $value)
138
    {
139
        $this->offsetSet($offset, $value);
140
    }
141
142
    // ------------------------------------------------------------------------
143
144
    /**
145
     * Environment::store
146
     *
147
     * Store the data into the storage.
148
     * An alias of Environment::__set method.
149
     *
150
     * @param string $offset The data offset key.
151
     * @param mixed  $value  The data to be stored.
152
     *
153
     * @return void
154
     */
155
    public function store($offset, $value)
156
    {
157
        $this->__set($offset, $value);
158
    }
159
160
    // ------------------------------------------------------------------------
161
162
    /**
163
     * Environment::offsetSet
164
     *
165
     * Offset to set
166
     *
167
     * @link  http://php.net/manual/en/arrayaccess.offsetset.php
168
     *
169
     * @param mixed $offset <p>
170
     *                      The offset to assign the value to.
171
     *                      </p>
172
     * @param mixed $value  <p>
173
     *                      The value to set.
174
     *                      </p>
175
     *
176
     * @return void
177
     * @since 5.0.0
178
     */
179
    public function offsetSet($offset, $value)
180
    {
181
        $_ENV[ $offset ] = $value;
182
    }
183
184
    // ------------------------------------------------------------------------
185
186
    /**
187
     * Environment::remove
188
     *
189
     * Removes a data from the storage.
190
     * An alias of Environment::__unset method.
191
     *
192
     * @param string $offset The object offset key.
193
     *
194
     * @return void
195
     */
196
    public function remove($offset)
197
    {
198
        $this->__unset($offset);
199
    }
200
201
    // ------------------------------------------------------------------------
202
203
    /**
204
     * Environment::__unset
205
     *
206
     * Implementing magic method __unset to simplify unset method, just simply calling
207
     * unset( $globals[ 'offset' ] ).
208
     *
209
     * @param mixed $offset PHP Native GLOBALS offset
210
     *
211
     * @return void
212
     */
213
    public function __unset($offset)
214
    {
215
        $this->offsetUnset($offset);
216
    }
217
218
    // ------------------------------------------------------------------------
219
220
    /**
221
     * Environment::offsetUnset
222
     *
223
     * Offset to unset
224
     *
225
     * @link  http://php.net/manual/en/arrayaccess.offsetunset.php
226
     *
227
     * @param mixed $offset <p>
228
     *                      The offset to unset.
229
     *                      </p>
230
     *
231
     * @return void
232
     * @since 5.0.0
233
     */
234
    public function offsetUnset($offset)
235
    {
236
        if (isset($_ENV[ $offset ])) {
237
            unset($_ENV[ $offset ]);
238
        }
239
    }
240
241
    // ------------------------------------------------------------------------
242
243
    /**
244
     * Environment::merge
245
     *
246
     * Merge new array of data into the data storage.
247
     *
248
     * @param array $data New array of data.
249
     *
250
     * @return array The old array of data storage.
251
     */
252
    public function merge(array $data)
253
    {
254
        $oldData = $_ENV;
255
        $_ENV = array_merge($_ENV, $data);
256
257
        return $oldData;
258
    }
259
260
    // ------------------------------------------------------------------------
261
262
    /**
263
     * Environment::exchange
264
     *
265
     * Exchange the array of data storage into the new array of data.
266
     *
267
     * @param array $data New array of data.
268
     *
269
     * @return array The old array of data storage.
270
     */
271
    public function exchange(array $data)
272
    {
273
        $oldData = $_ENV;
274
        $_ENV = $data;
275
276
        return $oldData;
277
    }
278
279
    // ------------------------------------------------------------------------
280
281
    /**
282
     * Environment::destroy
283
     *
284
     * Removes all object from the container and perform each object destruction.
285
     *
286
     * @return array Array of old storage items.
287
     */
288
    public function destroy()
289
    {
290
        $storage = $_ENV;
291
292
        $_ENV = [];
293
294
        return $storage;
295
    }
296
297
    // ------------------------------------------------------------------------
298
299
    /**
300
     * Environment::count
301
     *
302
     * Application of Countable::count method to count the numbers of contained objects.
303
     *
304
     * @see  http://php.net/manual/en/countable.count.php
305
     * @return int The numbers of data on the storage.
306
     */
307
    public function count()
308
    {
309
        return (int)count($_ENV);
310
    }
311
312
    // ------------------------------------------------------------------------
313
314
    /**
315
     * Environment::serialize
316
     *
317
     * Application of Serializable::serialize method to serialize the data storage.
318
     *
319
     * @see  http://php.net/manual/en/serializable.serialize.php
320
     *
321
     * @return string The string representation of the serialized data storage.
322
     */
323
    public function serialize()
324
    {
325
        return serialize($_ENV);
326
    }
327
328
    // ------------------------------------------------------------------------
329
330
    /**
331
     * Environment::unserialize
332
     *
333
     * Application of Serializable::unserialize method to unserialize and construct the data storage.
334
     *
335
     * @see  http://php.net/manual/en/serializable.unserialize.php
336
     *
337
     * @param string $serialized The string representation of the serialized data storage.
338
     *
339
     * @return void
340
     */
341
    public function unserialize($serialized)
342
    {
343
        $_ENV = unserialize($serialized);
344
    }
345
346
    // ------------------------------------------------------------------------
347
348
    /**
349
     * Environment::jsonSerialize
350
     *
351
     * Specify data which should be serialized to JSON
352
     *
353
     * @link  http://php.net/manual/en/jsonserializable.jsonserialize.php
354
     * @return mixed data which can be serialized by <b>json_encode</b>,
355
     *        which is a value of any type other than a resource.
356
     * @since 5.4.0
357
     */
358
    public function jsonSerialize()
359
    {
360
        return $_ENV;
361
    }
362
363
    // ------------------------------------------------------------------------
364
365
    /**
366
     * Environment::getArrayCopy
367
     *
368
     * Gets a copy of the data storage.
369
     *
370
     * @return array Returns a copy of the data storage.
371
     */
372
    public function getArrayCopy()
373
    {
374
        return $_ENV;
375
    }
376
377
    // ------------------------------------------------------------------------
378
379
    /**
380
     * Environment::get
381
     *
382
     * Finds an entry of the container by its identifier and returns it.
383
     *
384
     * @param string $id Identifier of the entry to look for.
385
     *
386
     * @throws NotFoundExceptionInterface  No entry was found for **this** identifier.
387
     * @throws ContainerExceptionInterface Error while retrieving the entry.
388
     *
389
     * @return mixed Entry.
390
     */
391
    public function get($id)
392
    {
393
        if ($this->has($id)) {
394
            return $this->offsetGet($id);
395
        }
396
397
        // @todo throw exception
398
    }
399
400
    // ------------------------------------------------------------------------
401
402
    /**
403
     * Environment::has
404
     *
405
     * Returns true if the container can return an entry for the given identifier.
406
     * Returns false otherwise.
407
     *
408
     * `has($id)` returning true does not mean that `get($id)` will not throw an exception.
409
     * It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
410
     *
411
     * @param string $id Identifier of the entry to look for.
412
     *
413
     * @return bool
414
     */
415
    public function has($id)
416
    {
417
        return (bool)$this->offsetExists($id);
418
    }
419
420
    // ------------------------------------------------------------------------
421
422
    /**
423
     * Environment::offsetGet
424
     *
425
     * Offset to retrieve
426
     *
427
     * @link  http://php.net/manual/en/arrayaccess.offsetget.php
428
     *
429
     * @param mixed $offset <p>
430
     *                      The offset to retrieve.
431
     *                      </p>
432
     *
433
     * @return mixed Can return all value types.
434
     * @since 5.0.0
435
     */
436
    public function offsetGet($offset)
437
    {
438
        return (isset($_ENV[ $offset ])) ? $_ENV[ $offset ] : false;
439
    }
440
}