ServerBag::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @license MIT
4
 */
5
namespace Pivasic\Bundle\Common\Bag;
6
7
/**
8
 * Class ServerBag
9
 * @package Pivasic\Bundle\Common\Bag
10
 */
11
class ServerBag extends ValueBag
12
{
13
    public function __construct()
14
    {
15
        parent::__construct($_SERVER);
16
    }
17
18
    /**
19
     * Returns a SERVER parameter by name.
20
     *
21
     * @param string $key
22
     * @param mixed|null $default The default value if the parameter key does not exist
23
     * @return mixed|null
24
     */
25
    public function fetch(string $key, $default = null)
26
    {
27
        if (isset($_SERVER[$key])) {
28
            return $_SERVER[$key];
29
        } else {
30
            $key = 'HTTP_' . $key;
31
            return $_SERVER[$key] ?? $default;
32
        }
33
    }
34
}