Passed
Push — master ( 9013bb...125cf1 )
by Kirill
03:56
created

ResponseFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Http\Diactoros;
13
14
use Psr\Http\Message\ResponseFactoryInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use Spiral\Http\Config\HttpConfig;
17
use Laminas\Diactoros\Response;
18
19
final class ResponseFactory implements ResponseFactoryInterface
20
{
21
    /** @var HttpConfig */
22
    protected $config;
23
24
    /**
25
     * @param HttpConfig $config
26
     */
27
    public function __construct(HttpConfig $config)
28
    {
29
        $this->config = $config;
30
    }
31
32
    /**
33
     * @param int    $code
34
     * @param string $reasonPhrase
35
     *
36
     * @return ResponseInterface
37
     */
38
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
39
    {
40
        $response = new Response('php://memory', $code, []);
41
        $response = $response->withStatus($code, $reasonPhrase);
42
43
        foreach ($this->config->getBaseHeaders() as $header => $value) {
44
            $response = $response->withAddedHeader($header, $value);
45
        }
46
47
        return $response;
48
    }
49
}
50