Conditions | 2 |
Paths | 1 |
Total Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
33 | 5 | public function __invoke(callable $handler): callable |
|
34 | { |
||
35 | return function(RequestInterface $request, array $options) use ($handler): PromiseInterface { |
||
36 | // Set starting time. |
||
37 | 4 | $start = microtime(true); |
|
38 | |||
39 | 4 | return $handler($request, $options) |
|
40 | ->then(function(ResponseInterface $response) use ($start, $request) { |
||
41 | // After |
||
42 | 1 | $this->profiler->add($start, microtime(true), $request, $response); |
|
43 | |||
44 | 1 | return $response; |
|
45 | }, function(ClientExceptionInterface $exception) use ($start, $request) { |
||
46 | 2 | $response = $exception instanceof RequestException ? $exception->getResponse() : null; |
|
47 | 2 | $this->profiler->add($start, microtime(true), $request, $response); |
|
48 | |||
49 | 2 | throw $exception; |
|
50 | 4 | }); |
|
51 | 5 | }; |
|
52 | } |
||
53 | } |
||
54 |