QuietMiddleware   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 2
B isQuiet() 0 20 6
1
<?php
2
3
namespace hiapi\Core\Http\Psr15\Middleware;
4
5
use hiapi\legacy\lib\deps\err;
6
use Laminas\Diactoros\Response;
7
use Lcobucci\ContentNegotiation\UnformattedResponse;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
13
class QuietMiddleware implements MiddlewareInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
19
    {
20
        $response = $handler->handle($request);
21
22
        return $this->isQuiet($request, $response) ? new Response() : $response;
23
    }
24
25
    private function isQuiet(ServerRequestInterface $request, ResponseInterface $response): bool
26
    {
27
        if (empty($request->getAttribute('quiet'))) {
28
            return false;
29
        }
30
31
        if (!$response instanceof UnformattedResponse) {
0 ignored issues
show
Bug introduced by
The class Lcobucci\ContentNegotiation\UnformattedResponse does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
32
            return false;
33
        }
34
35
        $data = $response->getUnformattedContent();
36
        if ($data instanceof \Throwable) {
37
            return false;
38
        }
39
        if (is_array($data) && err::is($data)) {
40
            return false;
41
        }
42
43
        return true;
44
    }
45
}
46