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 ( 9df56c...dbaa3f )
by Cees-Jan
02:13
created

ObservableBunny   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 83.87%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 66
ccs 26
cts 31
cp 0.8387
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B consume() 0 43 3
1
<?php declare(strict_types=1);
2
3
namespace WyriHaximus\React\ObservableBunny;
4
5
use Bunny\Async\Client;
6
use Bunny\Channel;
7
use Bunny\Message as BunnyMessage;
8
use Bunny\Protocol\MethodBasicConsumeOkFrame;
9
use React\EventLoop\LoopInterface;
10
use Rx\Subject\Subject;
11
12
final class ObservableBunny
13
{
14
    /**
15
     * @var LoopInterface
16
     */
17
    private $loop;
18
19
    /**
20
     * @var Client
21
     */
22
    private $bunny;
23
24
    /**
25
     * @param LoopInterface $loop
26
     * @param Client        $bunny
27
     */
28 1
    public function __construct(LoopInterface $loop, Client $bunny)
29
    {
30 1
        $this->loop = $loop;
31 1
        $this->bunny = $bunny;
32 1
    }
33
34 1
    public function consume(
35
        string $queue = '',
36
        string $consumerTag = '',
37
        bool $noLocal = false,
38
        bool $noAck = false,
39
        bool $exclusive = false,
40
        bool $nowait = false,
41
        array $arguments = []
42
    ): Subject {
43 1
        $subject = new Subject();
44 1
        $consumeArgs = [$queue, $consumerTag, $noLocal, $noAck, $exclusive, $nowait, $arguments];
45
46 1
        $channel = $this->bunny->channel();
47 1
        $channel->then(function (Channel $channel) use ($subject, $consumeArgs) {
0 ignored issues
show
Bug introduced by
The method then does only exist in React\Promise\PromiseInterface, but not in Bunny\Channel.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48 1
            $consumerTag = null;
49 1
            $timer = $this->loop->addPeriodicTimer(1, function () use ($channel, $subject, &$timer, &$consumerTag) {
50 1
                if (!$subject->isDisposed()) {
51
                    return;
52
                }
53
54 1
                $channel->cancel($consumerTag)->done([$subject, 'onComplete'], [$subject, 'onError']);
55 1
                $this->loop->cancelTimer($timer);
56 1
            });
57 1
            $channel->consume(
0 ignored issues
show
Bug introduced by
The method then does only exist in React\Promise\PromiseInterface, but not in Bunny\Protocol\MethodBasicConsumeOkFrame.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58 1
                function (BunnyMessage $message, Channel $channel) use ($subject, &$timer, &$consumerTag) {
59 1
                    if ($subject->isDisposed()) {
60
                        $channel->nack($message);
61
                        $channel->cancel($consumerTag)->done([$subject, 'onComplete'], [$subject, 'onError']);
62
                        $this->loop->cancelTimer($timer);
63
64
                        return;
65
                    }
66
67 1
                    $subject->onNext(new Message($message, $channel));
68 1
                },
69 1
                ...$consumeArgs
0 ignored issues
show
Documentation introduced by
$consumeArgs is of type array<integer,string|boo..."boolean","6":"array"}>, but the function expects a string.

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...
70 1
            )->then(function (MethodBasicConsumeOkFrame $response) use (&$consumerTag) {
71 1
                $consumerTag = $response->consumerTag;
72 1
            })->done(null, [$subject, 'onError']);
73 1
        })->done(null, [$subject, 'onError']);
74
75 1
        return $subject;
76
    }
77
}
78