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 ( f4188c...1089d8 )
by Cees-Jan
05:14 queued 03:27
created

Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 2 Features 0
Metric Value
wmc 5
c 6
b 2
f 0
lcom 1
cbo 3
dl 0
loc 51
ccs 0
cts 19
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A request() 0 5 1
A requestAsync() 0 11 1
A createRequest() 0 8 1
1
<?php
2
3
namespace WyriHaximus\Travis;
4
5
use GuzzleHttp\Psr7\Request;
6
use Psr\Http\Message\ResponseInterface;
7
use React\Promise\Deferred;
8
9
class Client
10
{
11
    const VERSION = '0.0.1-alpha1';
12
    const USER_AGENT = 'wyrihaximus/travis-client/' . self::VERSION;
13
    const API_VERSION = 'application/vnd.travis-ci.2+json';
14
    const API_HOST_OPEN_SOURCE = 'api.travis-ci.org';
15
    const API_HOST_PRO = 'api.travis-ci.com';
16
    const API_HOST = self::API_HOST_OPEN_SOURCE;
17
    const API_SCHEMA = 'https';
18
19
    /**
20
     * @var callable
21
     */
22
    protected $handler;
23
24
    public function __construct(callable $handler = null)
25
    {
26
        if ($handler === null) {
27
            $handler = \Aws\default_http_handler();
28
        }
29
30
        $this->handler = $handler;
31
    }
32
33
    public function request(EndpointInterface $endpoint)
34
    {
35
        $handler = $this->handler;
36
        return $endpoint->fromResponse($handler($endpoint->getRequest())->wait());
37
    }
38
39
    public function requestAsync(EndpointInterface $endpoint)
40
    {
41
        $deferred = new Deferred();
42
        $handler = $this->handler;
43
        $handler($endpoint->getRequest())->then(function (ResponseInterface $response) use ($deferred, $endpoint) {
44
            $deferred->resolve($endpoint->fromResponse($response));
45
        }, function ($error) use ($deferred) {
46
            $deferred->reject($error);
47
        });
48
        return $deferred->promise();
49
    }
50
51
    public function createRequest(string $method, string $path)
52
    {
53
        $url = self::API_SCHEMA . '://' . self::API_HOST . '/' . $path;
54
        return new Request($method, $url, [
55
            'User-Agent' => self::USER_AGENT,
56
            'Accept' => self::API_VERSION,
57
        ]);
58
    }
59
}
60