ZendDiactorosHttpFactory::response()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Thruster\HttpFactory;
6
7
use Psr\Http\Message\RequestFactoryInterface;
8
use Psr\Http\Message\ResponseFactoryInterface;
9
use Psr\Http\Message\ServerRequestFactoryInterface;
10
use Psr\Http\Message\StreamFactoryInterface;
11
use Psr\Http\Message\UploadedFileFactoryInterface;
12
use Psr\Http\Message\UriFactoryInterface;
13
use Zend\Diactoros\RequestFactory;
14
use Zend\Diactoros\ResponseFactory;
15
use Zend\Diactoros\ServerRequestFactory;
16
use Zend\Diactoros\StreamFactory;
17
use Zend\Diactoros\UploadedFileFactory;
18
use Zend\Diactoros\UriFactory;
19
20
/**
21
 * Class ZendDiactorosHttpFactory.
22
 *
23
 * @author  Aurimas Niekis <[email protected]>
24
 */
25
class ZendDiactorosHttpFactory implements HttpFactoryInterface
26
{
27
    /** @var RequestFactoryInterface */
28
    private $requestFactory;
29
30
    /** @var ResponseFactoryInterface */
31
    private $responseFactory;
32
33
    /** @var ServerRequestFactoryInterface */
34
    private $serverRequestFactory;
35
36
    /** @var StreamFactoryInterface */
37
    private $streamFactor;
38
39
    /** @var UploadedFileFactoryInterface */
40
    private $uploadedFileFactory;
41
42
    /** @var UriFactoryInterface */
43
    private $uriFactory;
44
45 3
    public function request(): RequestFactoryInterface
46
    {
47 3
        if (null !== $this->requestFactory) {
48
            return $this->requestFactory;
49
        }
50
51 3
        $this->requestFactory = new RequestFactory();
52
53 3
        return $this->requestFactory;
54
    }
55
56 3
    public function response(): ResponseFactoryInterface
57
    {
58 3
        if (null !== $this->responseFactory) {
59
            return $this->responseFactory;
60
        }
61
62 3
        $this->responseFactory = new ResponseFactory();
63
64 3
        return $this->responseFactory;
65
    }
66
67 3
    public function serverRequest(): ServerRequestFactoryInterface
68
    {
69 3
        if (null !== $this->serverRequestFactory) {
70
            return $this->serverRequestFactory;
71
        }
72
73 3
        $this->serverRequestFactory = new ServerRequestFactory();
74
75 3
        return $this->serverRequestFactory;
76
    }
77
78 3
    public function stream(): StreamFactoryInterface
79
    {
80 3
        if (null !== $this->streamFactor) {
81
            return $this->streamFactor;
82
        }
83
84 3
        $this->streamFactor = new StreamFactory();
85
86 3
        return $this->streamFactor;
87
    }
88
89 3
    public function uploadedFile(): UploadedFileFactoryInterface
90
    {
91 3
        if (null !== $this->uploadedFileFactory) {
92
            return $this->uploadedFileFactory;
93
        }
94
95 3
        $this->uploadedFileFactory = new UploadedFileFactory();
96
97 3
        return $this->uploadedFileFactory;
98
    }
99
100 3
    public function uri(): UriFactoryInterface
101
    {
102 3
        if (null !== $this->uriFactory) {
103
            return $this->uriFactory;
104
        }
105
106 3
        $this->uriFactory = new UriFactory();
107
108 3
        return $this->uriFactory;
109
    }
110
}
111