Completed
Push — master ( 49b0e8...1ed855 )
by Hannes
16:46
created

ExceptionMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 13 1
1
<?php
2
namespace GuzzleHttp\Profiling\Debugbar;
3
4
use DebugBar\DataCollector\ExceptionsCollector;
5
use GuzzleHttp\Exception\GuzzleException;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
class ExceptionMiddleware
10
{
11
    /**
12
     * @var \DebugBar\DataCollector\ExceptionsCollector
13
     */
14
    private $collector;
15
16
    /**
17
     * ExceptionMiddleware constructor.
18
     *
19
     * @param \DebugBar\DataCollector\ExceptionsCollector $collector
20
     */
21 3
    public function __construct(ExceptionsCollector $collector)
22
    {
23 3
        $this->collector = $collector;
24 3
    }
25
26
    /**
27
     * @param callable $handler
28
     *
29
     * @return callable
30
     */
31 3
    public function __invoke(callable $handler)
32
    {
33
        return function (RequestInterface $request, array $options) use ($handler) {
34 2
            return $handler($request, $options)
35
                ->then(function (ResponseInterface $response) {
36 1
                    return $response;
37 2
                }, function (GuzzleException $exception) {
38 1
                    $this->collector->addException($exception);
0 ignored issues
show
Documentation introduced by
$exception is of type object<GuzzleHttp\Exception\GuzzleException>, 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...
39
40 1
                    throw $exception;
41 2
                });
42 3
        };
43
    }
44
}
45