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 ( fce5ae...f51a54 )
by Cees-Jan
12:09 queued 06:40
created

ObservableBunny   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 6
dl 0
loc 82
ccs 34
cts 42
cp 0.8095
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A consume() 0 50 3
A cancelSubscription() 0 8 1
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 React\EventLoop\Timer\TimerInterface;
11
use Rx\Subject\Subject;
12
13
final class ObservableBunny
14
{
15
    /**
16
     * @var LoopInterface
17
     */
18
    private $loop;
19
20
    /**
21
     * @var Client
22
     */
23
    private $bunny;
24
25
    /**
26
     * @param LoopInterface $loop
27
     * @param Client        $bunny
28
     */
29 1
    public function __construct(LoopInterface $loop, Client $bunny)
30
    {
31 1
        $this->loop = $loop;
32 1
        $this->bunny = $bunny;
33 1
    }
34
35 1
    public function consume(
36
        string $queue = '',
37
        string $consumerTag = '',
38
        bool $noLocal = false,
39
        bool $noAck = false,
40
        bool $exclusive = false,
41
        bool $nowait = false,
42
        array $arguments = []
43
    ): Subject {
44 1
        $subject = new Subject();
45 1
        $consumeArgs = [$queue, $consumerTag, $noLocal, $noAck, $exclusive, $nowait, $arguments];
46
47 1
        $channel = $this->bunny->channel();
48 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...
49
            /** @var string $consumerTag */
50 1
            $consumerTag = null;
51 1
            $timer = $this->loop->addPeriodicTimer(1, function () use ($channel, $subject, &$timer, &$consumerTag) {
52 1
                if (!$subject->isDisposed()) {
53
                    return;
54
                }
55
56 1
                $this->cancelSubscription(
57 1
                    $timer,
58 1
                    $channel,
59 1
                    $consumerTag
60 1
                )->done([$subject, 'onComplete'], [$subject, 'onError']);
61 1
            });
62 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...
63 1
                function (BunnyMessage $message, Channel $channel) use ($subject, &$timer, &$consumerTag) {
64 1
                    if ($subject->isDisposed()) {
65
                        $channel->nack($message);
66
                        $this->cancelSubscription(
67
                            $timer,
68
                            $channel,
69
                            $consumerTag
70
                        )->done([$subject, 'onComplete'], [$subject, 'onError']);
71
72
                        return;
73
                    }
74
75 1
                    $subject->onNext(new Message($message, $channel));
76 1
                },
77 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...
78 1
            )->then(function (MethodBasicConsumeOkFrame $response) use (&$consumerTag) {
79 1
                $consumerTag = $response->consumerTag;
80 1
            })->done(null, [$subject, 'onError']);
81 1
        })->done(null, [$subject, 'onError']);
82
83 1
        return $subject;
84
    }
85
86 1
    private function cancelSubscription(TimerInterface $timer, Channel $channel, string $consumerTag)
87
    {
88 1
        $this->loop->cancelTimer($timer);
89
90 1
        return $channel->cancel($consumerTag)->then(function () use ($channel) {
91 1
            return $channel->close();
92 1
        });
93
    }
94
}
95