Completed
Push — master ( e43f1a...57db71 )
by Arman
26s queued 12s
created

Header   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 8
c 1
b 0
f 0
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A allHeaders() 0 3 1
A hasHeader() 0 3 1
A setHeader() 0 3 1
A getHeader() 0 3 2
A deleteHeader() 0 4 2
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.4.0
13
 */
14
15
namespace Quantum\Http\Request;
16
17
/**
18
 * Trait Header
19
 * @package Quantum\Http\Request
20
 */
21
trait Header
22
{
23
24
    /**
25
     * Request headers
26
     * @var array
27
     */
28
    private static $__headers = [];
29
30
    /**
31
     * Checks the request header existence by given key
32
     * @param string $key
33
     * @return bool
34
     */
35
    public static function hasHeader(string $key): bool
36
    {
37
        return isset(self::$__headers[strtolower($key)]);
38
    }
39
40
    /**
41
     * Gets the request header by given key
42
     * @param string $key
43
     * @return string|null
44
     */
45
    public static function getHeader(string $key): ?string
46
    {
47
        return self::hasHeader($key) ? self::$__headers[strtolower($key)] : null;
48
    }
49
50
    /**
51
     * Sets the request header
52
     * @param string $key
53
     * @param mixed $value
54
     */
55
    public static function setHeader(string $key, $value)
56
    {
57
        self::$__headers[strtolower($key)] = $value;
58
    }
59
60
    /**
61
     * Gets all request headers
62
     * @return array
63
     */
64
    public static function allHeaders(): array
65
    {
66
        return self::$__headers;
67
    }
68
69
    /**
70
     * Deletes the header by given key
71
     * @param string $key
72
     */
73
    public static function deleteHeader(string $key)
74
    {
75
        if (self::hasHeader($key)) {
76
            unset(self::$__headers[strtolower($key)]);
77
        }
78
    }
79
80
}