GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ae671f...7094e6 )
by David
02:14
created

ReplayPlugin::handleRequest()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\Client\Plugin\Vcr;
6
7
use Http\Client\Common\Plugin;
8
use Http\Client\Exception\RequestException;
9
use Http\Client\Plugin\Vcr\NamingStrategy\NamingStrategyInterface;
10
use Http\Client\Plugin\Vcr\Recorder\PlayerInterface;
11
use Http\Promise\FulfilledPromise;
12
use Http\Promise\Promise;
13
use Psr\Http\Message\RequestInterface;
14
15
final class ReplayPlugin implements Plugin
16
{
17
    const HEADER_NAME = 'X-VCR-REPLAYED';
18
19
    /**
20
     * @var NamingStrategyInterface
21
     */
22
    private $namingStrategy;
23
24
    /**
25
     * @var PlayerInterface
26
     */
27
    private $player;
28
29
    /**
30
     * Throw an exception if not able to replay a request.
31
     *
32
     * @var bool
33
     */
34
    private $throw;
35
36 2
    public function __construct(NamingStrategyInterface $namingStrategy, PlayerInterface $player, bool $throw = true)
37
    {
38 2
        $this->namingStrategy = $namingStrategy;
39 2
        $this->player = $player;
40 2
        $this->throw = $throw;
41 2
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 2
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
47
    {
48 2
        $name = $this->namingStrategy->name($request);
49
50 2
        if ($response = $this->player->replay($name)) {
51 1
            return new FulfilledPromise($response->withAddedHeader(static::HEADER_NAME, $name));
52
        }
53
54 2
        if ($this->throw) {
55 1
            throw new RequestException("Unable to find a response to replay request \"$name\".", $request);
56
        }
57
58 1
        return $next($request);
59
    }
60
61
    /**
62
     * Whenever the plugin should throw an exception when not able to replay a request.
63
     *
64
     * @return $this
65
     */
66 1
    public function throwOnNotFound(bool $throw)
67
    {
68 1
        $this->throw = $throw;
69
70 1
        return $this;
71
    }
72
}
73