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 ( a9556a...775799 )
by Cees-Jan
10s
created

AsyncClient::repositories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace ApiClients\Client\Travis;
5
6
use ApiClients\Client\Travis\CommandBus\Command;
7
use ApiClients\Client\Travis\Resource\HookInterface;
8
use ApiClients\Foundation\Client;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiClients\Client\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...
9
use ApiClients\Foundation\Factory;
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 ApiClients\Tools\Rx\unwrapObservableFromPromise;
17
use function React\Promise\resolve;
18
19
class AsyncClient
20
{
21
    /**
22
     * @var Client
23
     */
24
    protected $client;
25
26
    /**
27
     * @param LoopInterface $loop
28
     * @param string $token
29
     * @param array $options
30
     * @param Client|null $client
31
     */
32
    public function __construct(
33
        LoopInterface $loop,
34
        string $token = '',
35
        array $options = [],
36
        Client $client = null
37
    ) {
38
        if (!($client instanceof Client)) {
39
            $this->options = ApiSettings::getOptions($token, 'Async', $options);
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...
40
            $client = Factory::create($loop, $this->options);
41
        }
42
        $this->client = $client;
43
    }
44
45
    /**
46
     * @param string $repository
47
     * @return CancellablePromiseInterface
48
     */
49
    public function repository(string $repository): CancellablePromiseInterface
50
    {
51
        return $this->client->handle(new Command\RepositoryCommand($repository));
52
    }
53
54
    /**
55
     * @return ObservableInterface
56
     */
57
    public function repositories(): ObservableInterface
58
    {
59
        return $this->hooks()->filter(function ($hook) {
60
            return $hook->active();
61
        })->flatMap(function (HookInterface $hook) {
62
            return Promise::toObservable($this->client->handle(
63
                new Command\RepositoryIdCommand($hook->id())
64
            ));
65
        });
66
    }
67
68
    /**
69
     * @return PromiseInterface
70
     */
71
    public function user(): PromiseInterface
72
    {
73
        return $this->client->handle(new Command\UserCommand());
74
    }
75
76
    /**
77
     * @param int $id
78
     * @return PromiseInterface
79
     */
80
    public function sshKey(int $id): PromiseInterface
81
    {
82
        return $this->client->handle(new Command\SSHKeyCommand($id));
83
    }
84
85
    /**
86
     * @return ObservableInterface
87
     */
88
    public function hooks(): ObservableInterface
89
    {
90
        return unwrapObservableFromPromise($this->client->handle(
91
            new Command\HooksCommand()
92
        ));
93
    }
94
95
    /**
96
     * @return ObservableInterface
97
     */
98
    public function accounts(): ObservableInterface
99
    {
100
        return unwrapObservableFromPromise($this->client->handle(
101
            new Command\AccountsCommand()
102
        ));
103
    }
104
105
    /**
106
     * @return ObservableInterface
107
     */
108
    public function broadcasts(): ObservableInterface
109
    {
110
        return unwrapObservableFromPromise($this->client->handle(
111
            new Command\BroadcastsCommand()
112
        ));
113
    }
114
}
115