ResponseHeader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 49
ccs 0
cts 24
cp 0
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 5 2
A get() 0 10 2
A set() 0 10 3
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