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.

Oauth1Middleware   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 8
dl 0
loc 72
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateOptions() 0 23 5
A __construct() 0 4 1
A pre() 0 13 2
A signRequest() 0 10 1
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Middleware\Oauth1;
4
5
use ApiClients\Foundation\Middleware\DefaultPriorityTrait;
6
use ApiClients\Foundation\Middleware\ErrorTrait;
7
use ApiClients\Foundation\Middleware\MiddlewareInterface;
8
use ApiClients\Foundation\Middleware\PostTrait;
9
use ApiClients\Tools\Psr7\Oauth1\Definition;
10
use ApiClients\Tools\Psr7\Oauth1\RequestSigning\RequestSigner;
11
use Psr\Http\Message\RequestInterface;
12
use React\EventLoop\LoopInterface;
13
use React\Promise\CancellablePromiseInterface;
14
use function GuzzleHttp\Psr7\parse_query;
15
use function React\Promise\resolve;
16
use function WyriHaximus\React\futurePromise;
17
18
class Oauth1Middleware implements MiddlewareInterface
19
{
20
    use PostTrait;
21
    use ErrorTrait;
22
23
    /**
24
     * @var LoopInterface
25
     */
26
    private $loop;
27
28
    /**
29
     * @param LoopInterface $loop
30
     */
31 10
    public function __construct(LoopInterface $loop)
32
    {
33 10
        $this->loop = $loop;
34 10
    }
35
36
    /**
37
     * @param RequestInterface $request
38
     * @param array $options
39
     * @return CancellablePromiseInterface
40
     */
41 10
    public function pre(
42
        RequestInterface $request,
43
        string $transactionId,
44
        array $options = []
45
    ): CancellablePromiseInterface {
46 10
        if (!$this->validateOptions($options)) {
47 9
            return resolve($request);
48
        }
49
50 1
        return futurePromise($this->loop, [$request, $options])->then(function ($args) {
51 1
            return resolve($this->signRequest(...$args));
0 ignored issues
show
Bug introduced by
The call to signRequest() misses a required argument $options.

This check looks for function calls that miss required arguments.

Loading history...
52 1
        });
53
    }
54
55 10
    private function validateOptions(array $options): bool
56
    {
57 10
        if (!isset($options[self::class])) {
58 1
            return false;
59
        }
60
61
        foreach ([
62 9
            Options::CONSUMER_KEY,
63
            Options::CONSUMER_SECRET,
64
            Options::ACCESS_TOKEN,
65
            Options::TOKEN_SECRET,
66
        ] as $option) {
67 9
            if (!isset($options[self::class][$option])) {
68 4
                return false;
69
            }
70
71 8
            if (!($options[self::class][$option] instanceof $option)) {
72 8
                return false;
73
            }
74
        }
75
76 1
        return true;
77
    }
78
79 1
    private function signRequest(RequestInterface $request, array $options): RequestInterface
80
    {
81 1
        return (new RequestSigner(
82 1
            new Definition\ConsumerKey($options[self::class][Options::CONSUMER_KEY]),
83 1
            new Definition\ConsumerSecret($options[self::class][Options::CONSUMER_SECRET])
84 1
        ))->withAccessToken(
85 1
            new Definition\AccessToken($options[self::class][Options::ACCESS_TOKEN]),
86 1
            new Definition\TokenSecret($options[self::class][Options::TOKEN_SECRET])
87 1
        )->sign($request);
88
    }
89
}
90