Completed
Push — master ( 16c8a5...965897 )
by Michael
02:58
created

ServerResponse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 37
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A send() 0 12 4
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
 * @version 1.0.0
9
 */
10
11
namespace miBadger\Http;
12
13
use Psr\Http\Message\StreamInterface;
14
15
/**
16
 * The server request class
17
 *
18
 * @since 1.0.0
19
 */
20
class ServerResponse extends Response
21
{
22
	/**
23
	 * Construct a ServerResponse object with the given status code, reason phrase, version, headers & body.
24
	 *
25
	 * @param int $statusCode
26
	 * @param string $reasonPhrase = ''
27
	 * @param string $version = self::DEFAULT_VERSION
28
	 * @param array $headers = []
29
	 * @param StreamInterface|null $body = null
30
	 */
31 3
	public function __construct($statusCode, $reasonPhrase = '', $version = self::DEFAULT_VERSION, array $headers = [], StreamInterface $body = null)
32
	{
33 3
		if ($body === null) {
34 3
			$body = new Stream(fopen('php://output', 'w'));
35 3
		}
36
37 3
		parent::__construct($statusCode, $reasonPhrase, $version, $headers, $body);
38 3
	}
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 1
		}
49
50 1
		foreach ($this->getHeaders() as $key => $value) {
51 1
			header($key . static::HEADER_DELIMITER . implode(static::HEADER_VALUE_DELIMITER, $value));
52 1
		}
53
54 1
		echo $this->getBody();
55 1
	}
56
}
57