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.

ReplayPlugin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handleRequest() 0 14 3
A throwOnNotFound() 0 6 1
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