ServerBag   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fetch() 0 9 2
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
}