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
Pull Request — master (#3)
by Cees-Jan
02:25
created

AsyncClient::repositories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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