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

Header   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 10
c 1
b 0
f 0
dl 0
loc 75
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeader() 0 3 2
A deleteHeader() 0 4 2
A allHeaders() 0 3 1
A setContentType() 0 3 1
A hasHeader() 0 3 1
A setHeader() 0 3 1
A getContentType() 0 3 1
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\Response;
16
17
/**
18
 * Trait Header
19
 * @package Quantum\Http\Response
20
 */
21
trait Header
22
{
23
24
    /**
25
     * Response headers
26
     * @var array
27
     */
28
    private static $__headers = [];
29
30
    /**
31
     * Checks the response 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[$key]);
38
    }
39
40
    /**
41
     * Gets the response 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[$key] : null;
48
    }
49
50
    /**
51
     * Sets the response header
52
     * @param string $key
53
     * @param string $value
54
     */
55
    public static function setHeader(string $key, string $value)
56
    {
57
        self::$__headers[$key] = $value;
58
    }
59
60
    /**
61
     * Get all response 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[$key]);
77
        }
78
    }
79
80
    /**
81
     * Sets the content type
82
     * @param string $contentType
83
     */
84
    public static function setContentType(string $contentType)
85
    {
86
        self::setHeader('Content-Type', $contentType);
87
    }
88
89
    /**
90
     * Gets the content type
91
     * @return string|null
92
     */
93
    public static function getContentType(): ?string
94
    {
95
        return self::getHeader('Content-Type');
96
    }
97
98
}