ServerBag::__construct()   A
last analyzed

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