ExceptionMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 36
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 13 1
1
<?php
2
3
namespace GuzzleHttp\Profiling\Debugbar;
4
5
use DebugBar\DataCollector\ExceptionsCollector;
6
use GuzzleHttp\Promise\PromiseInterface;
7
use Psr\Http\Client\ClientExceptionInterface;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
class ExceptionMiddleware
12
{
13
    /**
14
     * @var \DebugBar\DataCollector\ExceptionsCollector
15
     */
16
    private $collector;
17
18
    /**
19
     * ExceptionMiddleware constructor.
20
     *
21
     * @param \DebugBar\DataCollector\ExceptionsCollector $collector
22
     */
23 3
    public function __construct(ExceptionsCollector $collector)
24
    {
25 3
        $this->collector = $collector;
26 3
    }
27
28
    /**
29
     * @param callable $handler
30
     *
31
     * @return callable
32
     */
33 3
    public function __invoke(callable $handler): callable
34
    {
35
        return function(RequestInterface $request, array $options) use ($handler): PromiseInterface {
36 2
            return $handler($request, $options)
37
                ->then(function(ResponseInterface $response) {
38 1
                    return $response;
39
                }, function(ClientExceptionInterface $exception) {
40 1
                    $this->collector->addException($exception);
0 ignored issues
show
Deprecated Code introduced by
The method DebugBar\DataCollector\E...llector::addException() has been deprecated with message: in favor on addThrowable

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
Documentation introduced by
$exception is of type object<Psr\Http\Client\ClientExceptionInterface>, but the function expects a object<Exception>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
42 1
                    throw $exception;
43 2
                });
44 3
        };
45
    }
46
}
47