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.

AsyncClient::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 6
cp 0
cc 2
eloc 5
nc 2
nop 3
crap 6
1
<?php
2
declare(strict_types=1);
3
4
namespace WyriHaximus\Travis;
5
6
use ApiClients\Foundation\Client;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, WyriHaximus\Travis\Client.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use ApiClients\Foundation\Factory;
8
use ApiClients\Foundation\Hydrator\CommandBus\Command\HydrateCommand;
9
use ApiClients\Foundation\Transport\CommandBus\Command\SimpleRequestCommand;
10
use React\EventLoop\LoopInterface;
11
use React\Promise\CancellablePromiseInterface;
12
use React\Promise\PromiseInterface;
13
use Rx\Observable;
14
use Rx\ObservableInterface;
15
use Rx\React\Promise;
16
use function React\Promise\resolve;
17
18
class AsyncClient
19
{
20
    /**
21
     * @var Client
22
     */
23
    protected $client;
24
25
    /**
26
     * @param LoopInterface $loop
27
     * @param string $token
28
     * @param Client|null $client
29
     */
30
    public function __construct(LoopInterface $loop, string $token = '', Client $client = null)
31
    {
32
        if (!($client instanceof Client)) {
33
            $this->options = ApiSettings::getOptions($token, 'Async');
0 ignored issues
show
Bug introduced by
The property options does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
            $client = Factory::create($loop, $this->options);
35
        }
36
        $this->client = $client;
37
    }
38
39
    /**
40
     * @param string $repository
41
     * @return CancellablePromiseInterface
42
     */
43
    public function repository(string $repository): CancellablePromiseInterface
44
    {
45
        return $this->client->handle(new SimpleRequestCommand('repos/' . $repository))->then(function ($response) {
46
            return $this->client->handle(new HydrateCommand('Repository', $response->getBody()->getJson()['repo']));
47
        });
48
    }
49
50
    /**
51
     * @return PromiseInterface
52
     */
53
    public function user(): PromiseInterface
54
    {
55
        return $this->client->handle(new SimpleRequestCommand('users'))->then(function ($response) {
56
            return $this->client->handle(new HydrateCommand('User', $response->getBody()->getJson()['user']));
57
        });
58
    }
59
60
    /**
61
     * @param int $id
62
     * @return PromiseInterface
63
     */
64
    public function sshKey(int $id): PromiseInterface
65
    {
66
        return $this->client->handle(new SimpleRequestCommand('settings/ssh_key/' . $id))->then(function ($response) {
67
            return $this->client->handle(new HydrateCommand('SSHKey', $response->getBody()->getJson()['ssh_key']));
68
        });
69
    }
70
71
    /**
72
     * @return ObservableInterface
73
     */
74
    public function hooks(): ObservableInterface
75
    {
76
        return Promise::toObservable(
77
            $this->client->handle(new SimpleRequestCommand('hooks'))
78
        )->flatMap(function ($response) {
79
            return Observable::fromArray($response->getBody()->getJson()['hooks']);
80
        })->flatMap(function ($hook) {
81
            return Promise::toObservable($this->client->handle(new HydrateCommand('Hook', $hook)));
82
        });
83
    }
84
85
    /**
86
     * @return ObservableInterface
87
     */
88
    public function accounts(): ObservableInterface
89
    {
90
        return Promise::toObservable(
91
            $this->client->handle(new SimpleRequestCommand('accounts'))
92
        )->flatMap(function ($response) {
93
            return Observable::fromArray($response->getBody()->getJson()['accounts']);
94
        })->flatMap(function ($account) {
95
            return Promise::toObservable($this->client->handle(new HydrateCommand('Account', $account)));
96
        });
97
    }
98
99
    /**
100
     * @return ObservableInterface
101
     */
102
    public function broadcasts(): ObservableInterface
103
    {
104
        return Promise::toObservable(
105
            $this->client->handle(new SimpleRequestCommand('broadcasts'))
106
        )->flatMap(function ($response) {
107
            return Observable::fromArray($response->getBody()->getJson()['broadcasts']);
108
        })->flatMap(function ($broadcast) {
109
            return Promise::toObservable($this->client->handle(new HydrateCommand('Broadcast', $broadcast)));
110
        });
111
    }
112
}
113