Completed
Push — 4.0 ( ed2d0a...2bab8b )
by Marco
15:57
created

Headers::remove()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 9

Duplication

Lines 21
Ratio 100 %
Metric Value
dl 21
loc 21
rs 9.3142
cc 3
eloc 9
nc 3
nop 1
1
<?php namespace Comodojo\Dispatcher\Components;
2
3
/**
4
 *
5
 * @package     Comodojo dispatcher
6
 * @author      Marco Giovinazzi <[email protected]>
7
 * @license     GPL-3.0+
8
 *
9
 * LICENSE:
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
trait Headers {
26
27
    protected $headers = array();
28
29
    final public function get($header = null) {
30
31
        if ( is_null($header) ) return $this->headers;
32
33
        else if ( array_key_exists($header, $this->headers) ) return $this->headers[$header];
34
35
        else return null;
36
37
    }
38
39
    final public function set($header, $value=null) {
40
41
        if ( is_null($value) ) {
42
43
            $header = explode(":", $header);
44
45
            $this->headers[$header[0]] = isset($header[1]) ? $header[1] : '';
46
47
        } else {
48
49
            $this->headers[$header] = $value;
50
51
        }
52
53
        return $this;
54
55
    }
56
57 View Code Duplication
    final public function remove($header = null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
59
        if ( is_null($header) ) {
60
61
            $this->headers = array();
62
63
            return true;
64
65
        } else if ( array_key_exists($header, $this->headers) ) {
66
67
            unset($this->headers[$header]);
68
69
            return true;
70
71
        } else {
72
73
            return false;
74
75
        }
76
77
    }
78
79
}
80