Passed
Pull Request — master (#73)
by Dmitriy
22:17 queued 07:13
created

DeferredResponseFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App;
4
5
use Nyholm\Psr7\Response;
6
use Psr\Http\Message\ResponseFactoryInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\StreamFactoryInterface;
9
10
class DeferredResponseFactory implements ResponseFactoryInterface
11
{
12
    private StreamFactoryInterface $streamFactory;
13
14
    public function __construct(StreamFactoryInterface $streamFactory)
15
    {
16
        $this->streamFactory = $streamFactory;
17
    }
18
19
    public function createResponse(int $code = 200, string $reasonPhrase = '', $data = null): ResponseInterface
20
    {
21
        return new DeferredResponse($data, $this->createResponseInternal(), $this->streamFactory);
22
    }
23
24
    private function createResponseInternal(int $code = 200, string $reasonPhrase = ''): ResponseInterface
25
    {
26
        if (2 > \func_num_args()) {
27
            // This will make the Response class to use a custom reasonPhrase
28
            $reasonPhrase = null;
29
        }
30
31
        return new Response($code, [], null, '1.1', $reasonPhrase);
32
    }
33
}
34