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

WebSocket   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 68.75%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 34
ccs 11
cts 16
cp 0.6875
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onNext() 0 4 1
A _subscribe() 0 17 1
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\ObserverInterface;
9
use Rx\Subject\ReplaySubject;
10
use Rx\Subject\Subject;
11
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...
12
13
/**
14
 * Class WebSocket - WebSocket wrapper that queues messages while the connection is being established.
15
 */
16
final class WebSocket extends Subject
17
{
18
    private $ws;
19
    private $sendSubject;
20
21 4
    public function __construct(string $url, bool $useMessageObject = false, array $subProtocols = [], LoopInterface $loop = null, Resolver $dnsResolver = null)
22
    {
23 4
        $this->sendSubject = new ReplaySubject();
24 4
        $this->ws = new Client($url, $useMessageObject, $subProtocols, $loop, $dnsResolver);
25 4
    }
26
27
    public function onNext($value)
28
    {
29
        $this->sendSubject->onNext($value);
30
    }
31
32 1
    protected function _subscribe(ObserverInterface $observer): DisposableInterface
33
    {
34 1
        return $this->ws
35 1
            ->do(function ($ms) {
36
                // Replay buffered messages onto the MessageSubject
37
                $this->sendSubject->subscribe($ms);
38
39
                // Now that the connection has been established, use the message subject directly.
40
                $this->sendSubject = $ms;
41 1
            })
42 1
            ->finally(function () {
43
                // The connection has closed, so start buffering messages util it reconnects.
44 1
                $this->sendSubject = new ReplaySubject();
45 1
            })
46
            ->mergeAll()
47
            ->subscribe($observer);
0 ignored issues
show
Documentation introduced by
$observer is of type object<Rx\ObserverInterface>, but the function expects a callable|null.

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...
48
    }
49
}
50