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

ServerBag::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 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