ResponseFactory::createResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 17
ccs 12
cts 12
cp 1
rs 9.9
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Shieldon\Psr17;
14
15
use Psr\Http\Message\ResponseFactoryInterface;
16
use Psr\Http\Message\ResponseInterface;
17
use Shieldon\Psr17\StreamFactory;
18
use Shieldon\Psr17\Utils\SuperGlobal;
19
use Shieldon\Psr7\Response;
20
21
use function str_replace;
22
use function extract;
23
24
/**
25
 * PSR-17 Response Factory
26
 */
27
class ResponseFactory implements ResponseFactoryInterface
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
33
    {
34 1
        extract(SuperGlobal::extract());
35
36 1
        $protocol = $server['SERVER_PROTOCOL'] ?? '1.1';
37 1
        $protocol = str_replace('HTTP/', '',  $protocol);
38
39 1
        $streamFactory = new streamFactory();
40
41 1
        $body = $streamFactory->createStream();
42
43 1
        return new Response(
44 1
            $code,
45 1
            $header, // from extract.
46 1
            $body,
47 1
            $protocol,
48 1
            $reasonPhrase
49 1
        );
50
    }
51
52
    /*
53
    |--------------------------------------------------------------------------
54
    | Non PSR-7 Methods.
55
    |--------------------------------------------------------------------------
56
    */
57
58
    /**
59
     * Create a new Response.
60
     *
61
     * @return ResponseInterface
62
     */
63 1
    public static function fromNew(): ResponseInterface
64
    {
65 1
        return new Response();
66
    }
67
}
68