ResponseHeader::set()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 12
rs 10
1
<?php
2
/**
3
 * @name      OpenImporter
4
 * @copyright OpenImporter contributors
5
 * @license   BSD https://opensource.org/licenses/BSD-3-Clause
6
 *
7
 * @version 1.0
8
 */
9
10
namespace OpenImporter;
11
12
/**
13
 * Any page served needs a header.
14
 *
15
 * @package OpenImporter
16
 */
17
class ResponseHeader
18
{
19
	protected $headers = array();
20
21
	/**
22
	 * Add a header
23
	 *
24
	 * @param string $key
25
	 * @param string|null $value (optional)
26
	 */
27
	public function set($key, $value = null)
28
	{
29
		if ($value === null && strpos($key, ':'))
30
		{
31
			$split = array_map('trim', explode(':', $key));
32
			$key = $split[0];
33
			$value = $split[1];
34
		}
35
36
		$this->headers[$key] = $value;
37
	}
38
39
	/**
40
	 * Send the headers
41
	 *
42
	 * @return string[]
43
	 */
44
	public function get()
45
	{
46
		$return = array();
47
48
		foreach ($this->headers as $key => $value)
49
		{
50
			$return[] = $key . ': ' . $value;
51
		}
52
53
		return $return;
54
	}
55
56
	/**
57
	 * Add a header
58
	 *
59
	 * @param string $key
60
	 */
61
	public function remove($key)
62
	{
63
		if (isset($this->headers[$key]))
64
		{
65
			unset($this->headers[$key]);
66
		}
67
	}
68
}
69