CustomResponseFactory::createResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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