WebContext::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 1
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