ExceptionThrower::handleRequest()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 1
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Esi\IPQuery.
7
 *
8
 * (c) Eric Sizemore <[email protected]>
9
 *
10
 * This source file is subject to the MIT license. For the full copyright and
11
 * license information, please view the LICENSE file that was distributed with
12
 * this source code.
13
 */
14
15
namespace Esi\IPQuery\HttpClient\Plugin;
16
17
use Http\Client\Common\Plugin;
18
use Http\Promise\Promise;
19
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Psr\Http\Message\RequestInterface;
21
use Psr\Http\Message\ResponseInterface;
22
use RuntimeException;
23
24
/**
25
 * @internal
26
 */
27
final class ExceptionThrower implements Plugin
28
{
29 4
    #[Override]
30
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
31
    {
32 4
        return $next($request)->then(static function (ResponseInterface $response): ResponseInterface {
33 4
            $status = $response->getStatusCode();
34
35 4
            if ($status >= 400 && $status < 600) {
36 2
                throw new RuntimeException($response->getReasonPhrase(), $status);
37
            }
38
39 2
            return $response;
40 4
        });
41
    }
42
}
43