WebContext   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 46
ccs 2
cts 2
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A get() 0 4 2
A __wakeup() 0 11 1
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