Test Failed
Branch feature__set_up_scrutinizer (ea6624)
by Robin
06:04 queued 02:46
created

ServerBag::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
namespace App\Support\Console;
4
5
6
class ServerBag
7
{
8
    /**
9
     * Hold the values
10
     *
11
     * @var array
12
     */
13
    protected $server;
14
15
    /**
16
     * ServerBag constructor. Allow us to override some values for testing.
17
     *
18
     * @param array|null $overrides
19
     */
20 50
    public function __construct(array $overrides = null)
21
    {
22 50
        $overrides = $overrides ? array_change_key_case($overrides, CASE_LOWER) : [];
23
24 50
        foreach ($_SERVER as $key => $value) {
25 50
            $key = strtolower($key);
26
27 50
            $this->server[$key] = $overrides[$key] ?? $value;
28
        }
29 50
    }
30
31
    /**
32
     * Get a server variable
33
     *
34
     * @param $key
35
     * @return mixed
36
     */
37 50
    public function get($key)
38
    {
39 50
        return $this->server[strtolower($key)];
40
    }
41
}
42