WebContext::__wakeup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the Ray.WebContextParam.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php MIT
6
 */
7
namespace Ray\WebContextParam;
8
9
class WebContext
10
{
11
    private $globals;
12
13
    /**
14
     * @param array $globals
15
     *
16
     * @SuppressWarnings(PHPMD.Superglobals)
17
     * @codeCoverageIgnore
18
     */
19
    public function __construct(
20
        array $globals = []
21
    ) {
22
        $this->globals = $globals ?: [
23
            '_ENV' => $_ENV,
24
            '_GET' => $_GET,
25
            '_POST' => $_POST,
26
            '_COOKIE' => $_COOKIE,
27
            '_SERVER' => $_SERVER
28
        ];
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 6
    public function get($key)
35
    {
36 6
        return isset($this->globals[$key]) ? $this->globals[$key] : [];
37
    }
38
39
    /**
40
     * @SuppressWarnings(PHPMD.Superglobals)
41
     * @codeCoverageIgnore
42
     */
43
    public function __wakeup()
44
    {
45
        $this->globals =
46
        [
47
            '_ENV' => $_ENV,
48
            '_GET' => $_GET,
49
            '_POST' => $_POST,
50
            '_COOKIE' => $_COOKIE,
51
            '_SERVER' => $_SERVER
52
        ];
53
    }
54
}
55