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 ( 3abaaf...dcd0c7 )
by Cees-Jan
8s
created

Client   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 64
ccs 0
cts 23
cp 0
rs 10
c 4
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A request() 0 11 1
A getHydrator() 0 4 1
A createRequest() 0 8 1
A getLoop() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis\Transport;
5
6
use GuzzleHttp\Psr7\Request;
7
use Psr\Http\Message\ResponseInterface;
8
use React\EventLoop\LoopInterface;
9
use React\Promise\Deferred;
10
use WyriHaximus\Travis\Resource\Async;
11
use WyriHaximus\Travis\Resource\Sync;
12
13
class Client
14
{
15
    const VERSION = '0.0.1-alpha1';
16
    const USER_AGENT = 'wyrihaximus/travis-client/' . self::VERSION;
17
    const API_VERSION = 'application/vnd.travis-ci.2+json';
18
    const API_HOST_OPEN_SOURCE = 'api.travis-ci.org';
19
    const API_HOST_PRO = 'api.travis-ci.com';
20
    const API_HOST = self::API_HOST_OPEN_SOURCE;
21
    const API_SCHEMA = 'https';
22
23
    /**
24
     * @var callable
25
     */
26
    protected $handler;
27
    protected $loop;
28
    protected $options = [];
29
    protected $hydrator;
30
31
    public function __construct(LoopInterface $loop, callable $handler = null, $options = [])
32
    {
33
        $this->loop = $loop;
34
        if ($handler === null) {
35
            $handler = \Aws\default_http_handler();
36
        }
37
38
        $this->handler = $handler;
39
        $this->options = $options;
40
        $this->hydrator = new Hydrator($this, $options);
41
    }
42
43
    public function request($path)
44
    {
45
        $deferred = new Deferred();
46
        $handler = $this->handler;
47
        $handler($this->createRequest('GET', $path))->then(function (ResponseInterface $response) use ($deferred) {
48
            $deferred->resolve(json_decode($response->getBody()->getContents(), true));
49
        }, function ($error) use ($deferred) {
50
            $deferred->reject($error);
51
        });
52
        return $deferred->promise();
53
    }
54
55
    public function getHydrator(): Hydrator
56
    {
57
        return $this->hydrator;
58
    }
59
60
    protected function createRequest(string $method, string $path)
61
    {
62
        $url = self::API_SCHEMA . '://' . self::API_HOST . '/' . $path;
63
        return new Request($method, $url, [
64
            'User-Agent' => self::USER_AGENT,
65
            'Accept' => self::API_VERSION,
66
        ]);
67
    }
68
69
    /**
70
     * @return LoopInterface
71
     */
72
    public function getLoop()
73
    {
74
        return $this->loop;
75
    }
76
}
77