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::createRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 2
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