CustomResponseFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createResponse() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HttpSoft\Basis\Response;
6
7
use HttpSoft\Message\Response;
8
use Psr\Http\Message\ResponseFactoryInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Psr\Http\Message\StreamInterface;
11
12
final class CustomResponseFactory implements ResponseFactoryInterface
13
{
14
    /**
15
     * @var array
16
     */
17
    private array $headers;
18
19
    /**
20
     * @var StreamInterface|string|resource
21
     */
22
    private $body;
23
24
    /**
25
     * @var string
26
     */
27
    private string $protocol;
28
29
    /**
30
     * @param array|null $headers
31
     * @param StreamInterface|string|resource $body
32
     * @param string $protocol
33
     */
34 59
    public function __construct(array $headers = null, $body = 'php://temp', string $protocol = '1.1')
35
    {
36 59
        $this->headers = $headers ?? ['Content-Type' => 'text/html; charset=UTF-8'];
37 59
        $this->body = $body;
38 59
        $this->protocol = $protocol;
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 14
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
45
    {
46 14
        return new Response($code, $this->headers, $this->body, $this->protocol, $reasonPhrase);
47
    }
48
}
49