Headers   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 4
A set() 0 10 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: las
5
 * Date: 28/06/2016
6
 * Time: 22:22
7
 */
8
namespace Venus\lib\Request;
9
10
class Headers implements RequestInterface
11
{
12
    /**
13
     * get parameter
14
     * @param string $name
15
     * @param string $default
16
     * @return string
17
     */
18
    public function get(string $name, string $default = null) : string
19
    {
20
        if (isset(apache_request_headers()[$name]) && apache_request_headers()[$name] != '') {
21
            return apache_request_headers()[$name];
22
        } else if ($default !== null) {
23
            return $default;
24
        }
25
    }
26
27
    /**
28
     * set a new header
29
     * @param string $name
30
     * @param string $value
31
     * @return string|Headers
32
     */
33
    public function set(string $name, string $value = null) : Headers
34
    {
35
        if ($value !== null) {
36
            header($name . ': ' . $value);
37
        } else {
38
            header($name);
39
        }
40
        
41
        return $this;
42
    }
43
}
44