Passed
Push — master ( 9013bb...125cf1 )
by Kirill
03:56
created

ServerBag   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 5 1
A normalize() 0 3 1
A get() 0 3 1
A has() 0 3 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Http\Request;
13
14
/**
15
 * Access to server parameters of request, every requested key will be normalized for better
16
 * usability.
17
 */
18
final class ServerBag extends InputBag
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function has(string $name): bool
24
    {
25
        return parent::has($this->normalize($name));
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function get(string $name, $default = null)
32
    {
33
        return parent::get($this->normalize($name), $default);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function fetch(array $keys, bool $fill = false, $filler = null)
40
    {
41
        $keys = array_map([$this, 'normalize'], $keys);
42
43
        return parent::fetch($keys, $fill, $filler);
44
    }
45
46
    /**
47
     * Normalizing name to simplify selection.
48
     *
49
     * @param string $name
50
     *
51
     * @return string
52
     */
53
    protected function normalize(string $name): string
54
    {
55
        return preg_replace('/[^a-z\.]/i', '_', strtoupper($name));
56
    }
57
}
58