Completed
Push — master ( 3d8aa7...80558b )
by Timo
02:25
created

Cache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A request() 0 15 3
1
<?php
2
3
namespace hamburgscleanest\GuzzleAdvancedThrottle\Cache\Strategies;
4
5
use GuzzleHttp\Promise\FulfilledPromise;
6
use GuzzleHttp\Promise\PromiseInterface;
7
use Psr\Http\Message\RequestInterface;
8
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
9
10
/**
11
 * Class Cache
12
 * @package hamburgscleanest\GuzzleAdvancedThrottle\Cache\Strategies
13
 */
14
class Cache extends Cachable
15
{
16
17
    /**
18
     * @param RequestInterface $request
19
     * @param callable $handler
20
     * @return PromiseInterface
21
     * @throws \InvalidArgumentException
22
     * @throws \Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException
23
     */
24 1
    public function request(RequestInterface $request, callable $handler) : PromiseInterface
25
    {
26
        try
27
        {
28 1
            return parent::request($request, $handler);
29
        }
30 1
        catch (TooManyRequestsHttpException $tooManyRequestsHttpException)
31
        {
32 1
            $response = $this->_getResponse($request);
33 1
            if ($response !== null)
34
            {
35 1
                return new FulfilledPromise($response);
36
            }
37
38
            throw $tooManyRequestsHttpException;
39
        }
40
    }
41
}