Conditions | 15 |
Paths | 200 |
Total Lines | 82 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
207 | public function send(): ResponseInterface |
||
208 | { |
||
209 | // Process URI based on the OpenAPI schema |
||
210 | $uriSchema = new Uri($this->schema->getServerUrl()); |
||
|
|||
211 | |||
212 | if (empty($uriSchema->getScheme())) { |
||
213 | $uriSchema = $uriSchema->withScheme($this->psr7Request->getUri()->getScheme()); |
||
214 | } |
||
215 | |||
216 | if (empty($uriSchema->getHost())) { |
||
217 | $uriSchema = $uriSchema->withHost($this->psr7Request->getUri()->getHost()); |
||
218 | } |
||
219 | |||
220 | $uri = $this->psr7Request->getUri() |
||
221 | ->withScheme($uriSchema->getScheme()) |
||
222 | ->withHost($uriSchema->getHost()) |
||
223 | ->withPort($uriSchema->getPort()) |
||
224 | ->withPath($uriSchema->getPath() . $this->psr7Request->getUri()->getPath()); |
||
225 | |||
226 | if (!preg_match("~^{$this->schema->getBasePath()}~", $uri->getPath())) { |
||
227 | $uri = $uri->withPath($this->schema->getBasePath() . $uri->getPath()); |
||
228 | } |
||
229 | |||
230 | $this->psr7Request = $this->psr7Request->withUri($uri); |
||
231 | |||
232 | // Prepare Body to Match Against Specification |
||
233 | $requestBody = $this->psr7Request->getBody()->getContents(); |
||
234 | if (!empty($requestBody)) { |
||
235 | $contentType = $this->psr7Request->getHeaderLine("content-type"); |
||
236 | if (empty($contentType) || str_contains($contentType, "application/json")) { |
||
237 | $requestBody = json_decode($requestBody, true); |
||
238 | } elseif (str_contains($contentType, "multipart/")) { |
||
239 | $requestBody = $this->parseMultiPartForm($contentType, $requestBody); |
||
240 | } else { |
||
241 | throw new InvalidRequestException("Cannot handle Content Type '$contentType'"); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | // Check if the body is the expected before request |
||
246 | $bodyRequestDef = $this->schema->getRequestParameters($this->psr7Request->getUri()->getPath(), $this->psr7Request->getMethod()); |
||
247 | $bodyRequestDef->match($requestBody); |
||
248 | |||
249 | // Handle Request |
||
250 | $response = $this->handleRequest($this->psr7Request); |
||
251 | $responseHeader = $response->getHeaders(); |
||
252 | $responseBodyStr = (string) $response->getBody(); |
||
253 | $responseBody = json_decode($responseBodyStr, true); |
||
254 | $statusReturned = $response->getStatusCode(); |
||
255 | |||
256 | // Assert results |
||
257 | if ($this->statusExpected != $statusReturned) { |
||
258 | throw new StatusCodeNotMatchedException( |
||
259 | "Status code not matched: Expected $this->statusExpected, got $statusReturned", |
||
260 | $responseBody |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | $bodyResponseDef = $this->schema->getResponseParameters( |
||
265 | $this->psr7Request->getUri()->getPath(), |
||
266 | $this->psr7Request->getMethod(), |
||
267 | $this->statusExpected |
||
268 | ); |
||
269 | $bodyResponseDef->match($responseBody); |
||
270 | |||
271 | foreach ($this->assertHeader as $key => $value) { |
||
272 | if (!isset($responseHeader[$key]) || !str_contains($responseHeader[$key][0], $value)) { |
||
273 | throw new NotMatchedException( |
||
274 | "Does not exists header '$key' with value '$value'", |
||
275 | $responseHeader |
||
276 | ); |
||
277 | } |
||
278 | } |
||
279 | |||
280 | if (!empty($responseBodyStr)) { |
||
281 | foreach ($this->assertBody as $item) { |
||
282 | if (!str_contains($responseBodyStr, $item)) { |
||
283 | throw new NotMatchedException("Body does not contain '$item'"); |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | |||
288 | return $response; |
||
289 | } |
||
324 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.