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 ( bf97e9...d06bac )
by Cees-Jan
12s
created

WebSocket::createFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 5
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Client\Pusher;
4
5
use React\Dns\Resolver\Resolver;
6
use React\EventLoop\LoopInterface;
7
use Rx\DisposableInterface;
8
use Rx\Observable;
9
use Rx\ObserverInterface;
10
use Rx\Subject\ReplaySubject;
11
use Rx\Subject\Subject;
12
use Rx\Websocket\Client;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ApiClients\Client\Pusher\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...
13
14
/**
15
 * Class WebSocket - WebSocket wrapper that queues messages while the connection is being established.
16
 */
17
final class WebSocket extends Subject
18
{
19
    private $ws;
20
    private $sendSubject;
21
22
    /**
23
     * @internal
24
     * @param  Observable                $ws
25
     * @throws \InvalidArgumentException
26
     */
27
    public function __construct(Observable $ws)
28
    {
29
        $this->sendSubject = new ReplaySubject();
30
        $this->ws = $ws;
31
    }
32
33
    public static function createFactory(string $url, bool $useMessageObject = false, array $subProtocols = [], LoopInterface $loop = null, Resolver $resolver = null): Subject
34
    {
35
        return new self(
36
            new Client($url, $useMessageObject, $subProtocols, $loop, $resolver)
37
        );
38
    }
39
40
    public function onNext($value)
41
    {
42
        $this->sendSubject->onNext($value);
43
    }
44
45
    protected function _subscribe(ObserverInterface $observer): DisposableInterface
46
    {
47
        return $this->ws
48
            ->do(function (Subject $ms) {
49
                // Replay buffered messages onto the MessageSubject
50
                $this->sendSubject->subscribe($ms);
51
52
                // Now that the connection has been established, use the message subject directly.
53
                $this->sendSubject = $ms;
54
            })
55
            ->finally(function () {
56
                // The connection has closed, so start buffering messages util it reconnects.
57
                $this->sendSubject = new ReplaySubject();
58
            })
59
            ->switch()
60
            ->repeatDelay()
61
            ->subscribe($observer);
62
    }
63
}
64