Middleware   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 177
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 118
dl 0
loc 177
rs 10
c 0
b 0
f 0
ccs 58
cts 58
cp 1
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A destroyRequestHandler() 0 3 1
A buildResponse() 0 21 1
A destroyBody() 0 3 1
A buildRequestHandler() 0 6 1
A destroyResponse() 0 3 1
A buildUploadedFile() 0 13 1
A destroyUploadedFile() 0 3 1
A buildRequest() 0 37 1
A destroyUri() 0 3 1
A buildBody() 0 22 1
A destroyRequest() 0 3 1
A buildUri() 0 23 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VM\Psr15Mocks;
6
use Psr\Http\Message\UriInterface;
7
use Psr\Http\Message\StreamInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\UploadedFileInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
13
trait Middleware
14
{
15
    private $response;
16
    private $request;
17
    private $requestHandler;
18
    private $body;
19
    private $uri;
20
    private $uploadedFile;
21
22 1
    private function buildResponse(): void
23
    {
24 1
        $this->response = $this->getMockBuilder(ResponseInterface::class)
0 ignored issues
show
Bug introduced by
It seems like getMockBuilder() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        $this->response = $this->/** @scrutinizer ignore-call */ getMockBuilder(ResponseInterface::class)
Loading history...
25 1
            ->disableOriginalConstructor()
26 1
            ->setMethods([
27 1
                'getStatusCode',
28
                'withStatus',
29
                'getReasonPhrase',
30
                'getProtocolVersion',
31
                'withProtocolVersion',
32
                'getHeaders',
33
                'hasHeader',
34
                'getHeader',
35
                'getHeaderLine',
36
                'withHeader',
37
                'withAddedHeader',
38
                'withoutHeader',
39
                'getBody',
40
                'withBody',
41
            ])
42 1
            ->getMock()
43
        ;
44 1
    }
45
46 1
    private function destroyResponse(): void
47
    {
48 1
        $this->response = null;
49 1
    }
50
51 1
    public function buildRequest(): void
52
    {
53 1
        $this->request = $this->getMockBuilder(ServerRequestInterface::class)
54 1
            ->disableOriginalConstructor()
55 1
            ->setMethods([
56 1
                'getServerParams',
57
                'getCookieParams',
58
                'withCookieParams',
59
                'getQueryParams',
60
                'withQueryParams',
61
                'getUploadedFiles',
62
                'withUploadedFiles',
63
                'getParsedBody',
64
                'withParsedBody',
65
                'getAttributes',
66
                'getAttribute',
67
                'withAttribute',
68
                'withoutAttribute',
69
                'getProtocolVersion',
70
                'withProtocolVersion',
71
                'getHeaders',
72
                'hasHeader',
73
                'getHeader',
74
                'getHeaderLine',
75
                'withHeader',
76
                'withAddedHeader',
77
                'withoutHeader',
78
                'getBody',
79
                'withBody',
80
                'getRequestTarget',
81
                'withRequestTarget',
82
                'getMethod',
83
                'withMethod',
84
                'getUri',
85
                'withUri',
86
            ])
87 1
            ->getMock()
88
        ;
89 1
    }
90
91 1
    private function destroyRequest(): void
92
    {
93 1
        $this->request = null;
94 1
    }
95
96 1
    private function buildBody(): void
97
    {
98 1
        $this->body = $this->getMockBuilder(StreamInterface::class)
99 1
            ->disableOriginalConstructor()
100 1
            ->setMethods([
101 1
                '__toString',
102
                'close',
103
                'detach',
104
                'getSize',
105
                'tell',
106
                'eof',
107
                'isSeekable',
108
                'seek',
109
                'rewind',
110
                'isWritable',
111
                'write',
112
                'isReadable',
113
                'read',
114
                'getContents',
115
                'getMetadata',
116
            ])
117 1
            ->getMock()
118
        ;
119 1
    }
120
121 1
    private function destroyBody(): void
122
    {
123 1
        $this->body = null;
124 1
    }
125
126 1
    private function buildRequestHandler(): void
127
    {
128 1
        $this->requestHandler = $this->getMockBuilder(RequestHandlerInterface::class)
129 1
            ->disableOriginalConstructor()
130 1
            ->setMethods(['handle'])
131 1
            ->getMock()
132
        ;
133 1
    }
134
135 1
    private function destroyRequestHandler(): void
136
    {
137 1
        $this->requestHandler = null;
138 1
    }
139
140 1
    private function buildUri(): void
141
    {
142 1
        $this->uri = $this->getMockBuilder(UriInterface::class)
143 1
            ->disableOriginalConstructor()
144 1
            ->setMethods([
145 1
                'getScheme',
146
                'getAuthority',
147
                'getUserInfo',
148
                'getHost',
149
                'getPort',
150
                'getPath',
151
                'getQuery',
152
                'getFragment',
153
                'withScheme',
154
                'withUserInfo',
155
                'withHost',
156
                'withPort',
157
                'withPath',
158
                'withQuery',
159
                'withFragment',
160
                '__toString',
161
            ])
162 1
            ->getMock()
163
        ;
164 1
    }
165
166 1
    private function destroyUri(): void
167
    {
168 1
        $this->uri = null;
169 1
    }
170
171 1
    private function buildUploadedFile(): void
172
    {
173 1
        $this->uploadedFile = $this->getMockBuilder(UploadedFileInterface::class)
174 1
            ->disableOriginalConstructor()
175 1
            ->setMethods([
176 1
                'getStream',
177
                'moveTo',
178
                'getSize',
179
                'getError',
180
                'getClientFilename',
181
                'getClientMediaType',
182
            ])
183 1
            ->getMock()
184
        ;
185 1
    }
186
187 1
    private function destroyUploadedFile(): void
188
    {
189 1
        $this->uploadedFile = null;
190 1
    }
191
}
192