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
05:34
created

functions.php ➔ setAsyncScheduler()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\Rx;
4
5
use Exception;
6
use React\EventLoop\LoopInterface;
7
use React\Promise\PromiseInterface;
8
use Rx\Observable;
9
use Rx\ObserverInterface;
10
use Rx\Scheduler;
11
use Throwable;
12
use function React\Promise\resolve;
13
14
/**
15
 * Take an observable from a promise and return an new observable piping through the stream.
16
 *
17
 * @param PromiseInterface $promise
18
 * @return Observable
19
 */
20
function unwrapObservableFromPromise(PromiseInterface $promise): Observable
21
{
22
    return Observable::create(
23
        function (
24
            ObserverInterface $observer
25
        ) use ($promise) {
26
            resolve($promise)->done(function (Observable $observable) use ($observer) {
27
                $observable->subscribe(
28
                    function ($next) use ($observer) {
29
                        $observer->onNext($next);
30
                    },
31
                    function ($error) use ($observer) {
32
                        $observer->onError($error);
33
                    },
34
                    function () use ($observer) {
35
                        $observer->onCompleted();
36
                    }
37
                );
38
            });
39
        }
40
    );
41
}
42
43
/**
44
 * Take an array and return an observable from it with an immediate scheduler for scheduling
45
 *
46
 * @param array $array
47
 * @return Observable
48
 */
49
function observableFromArray(array $array): Observable
50
{
51
    return Observable::fromArray($array, Scheduler::getImmediate());
52
}
53
54
/**
55
 * @param LoopInterface $loop
56
 * @throws Throwable
57
 */
58
function setAsyncScheduler(LoopInterface $loop)
59
{
60
    try {
61
        Scheduler::setAsyncFactory(function () use ($loop) {
62
            return new Scheduler\EventLoopScheduler($loop);
0 ignored issues
show
Documentation introduced by
$loop is of type object<React\EventLoop\LoopInterface>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
        });
64
    } catch (Exception $e) {
65
        if ($e->getMessage() === 'The async factory can not be set after the scheduler has been created') {
66
            return;
67
        }
68
69
        throw $e;
70
    }
71
}
72