ServerResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 11 4
A __construct() 0 7 2
1
<?php
2
3
/**
4
 * This file is part of the miBadger package.
5
 *
6
 * @author Michael Webbers <[email protected]>
7
 * @license http://opensource.org/licenses/Apache-2.0 Apache v2 License
8
 */
9
10
namespace miBadger\Http;
11
12
use Psr\Http\Message\StreamInterface;
13
14
/**
15
 * The server request class
16
 *
17
 * @since 1.0.0
18
 */
19
class ServerResponse extends Response
20
{
21
	/**
22
	 * Construct a ServerResponse object with the given status code, reason phrase, version, headers & body.
23
	 *
24
	 * @param int $statusCode
25
	 * @param string $reasonPhrase = ''
26
	 * @param string $version = self::DEFAULT_VERSION
27
	 * @param array $headers = []
28
	 * @param StreamInterface|null $body = null
29
	 */
30 3
	public function __construct($statusCode, $reasonPhrase = '', $version = self::DEFAULT_VERSION, array $headers = [], StreamInterface $body = null)
31
	{
32 3
		if ($body === null) {
33 3
			$body = new Stream(fopen('php://output', 'w'));
34
		}
35
36 3
		parent::__construct($statusCode, $reasonPhrase, $version, $headers, $body);
37 3
	}
38
39
	/**
40
	 * Send the server response.
41
	 *
42
	 * @return null
43
	 */
44 1
	public function send()
45
	{
46 1
		if ($this->getProtocolVersion() && $this->getStatusCode()) {
47 1
			header(static::VERSION_DELIMITER . $this->getProtocolVersion() . ' ' . $this->getStatusCode() . ' ' . $this->getReasonPhrase());
48
		}
49
50 1
		foreach ($this->getHeaders() as $key => $value) {
51 1
			header($key . static::HEADER_DELIMITER . implode(static::HEADER_VALUE_DELIMITER, $value));
52
		}
53
54 1
		echo $this->getBody();
55 1
	}
56
}
57