WyriHaximus /
reactphp-observable-bunny
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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\TimerInterface; |
||
| 11 | use React\Promise\PromiseInterface; |
||
| 12 | use Rx\Subject\Subject; |
||
| 13 | use Throwable; |
||
| 14 | |||
| 15 | final class ObservableBunny |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var LoopInterface |
||
| 19 | */ |
||
| 20 | private $loop; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var Client |
||
| 24 | */ |
||
| 25 | private $bunny; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var float |
||
| 29 | */ |
||
| 30 | private $checkInterval; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param LoopInterface $loop |
||
| 34 | * @param Client $bunny |
||
| 35 | * @param float $checkInterval |
||
| 36 | */ |
||
| 37 | 4 | public function __construct(LoopInterface $loop, Client $bunny, float $checkInterval = 1.0) |
|
| 38 | { |
||
| 39 | 4 | $this->loop = $loop; |
|
| 40 | 4 | $this->bunny = $bunny; |
|
| 41 | 4 | $this->checkInterval = $checkInterval; |
|
| 42 | 4 | } |
|
| 43 | |||
| 44 | 4 | public function consume( |
|
| 45 | string $queue = '', |
||
| 46 | array $qos = [], |
||
| 47 | string $consumerTag = '', |
||
| 48 | bool $noLocal = false, |
||
| 49 | bool $noAck = false, |
||
| 50 | bool $exclusive = false, |
||
| 51 | bool $nowait = false, |
||
| 52 | array $arguments = [] |
||
| 53 | ): Subject { |
||
| 54 | 4 | $subject = new Subject(); |
|
| 55 | 4 | $consumeArgs = [$queue, $consumerTag, $noLocal, $noAck, $exclusive, $nowait, $arguments]; |
|
| 56 | |||
| 57 | 4 | $channel = $this->bunny->channel(); |
|
| 58 | 3 | $channel->then(function (Channel $channel) use ($qos) { |
|
|
0 ignored issues
–
show
|
|||
| 59 | 3 | if (count($qos) === 0) { |
|
| 60 | 2 | return $channel; |
|
| 61 | } |
||
| 62 | |||
| 63 | 1 | return $channel->qos(...$qos)->then(function () use ($channel) { |
|
|
0 ignored issues
–
show
$qos is of type array, but the function expects a integer.
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...
The method
then does only exist in React\Promise\PromiseInterface, but not in Bunny\Protocol\MethodBasicQosOkFrame.
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
Loading history...
|
|||
| 64 | 1 | return $channel; |
|
| 65 | 1 | }); |
|
| 66 | })->then(function (Channel $channel) use ($subject, $consumeArgs) { |
||
| 67 | /** @var string $consumerTag */ |
||
| 68 | 3 | $consumerTag = null; |
|
| 69 | 3 | $timer = $this->loop->addPeriodicTimer($this->checkInterval, function () use ($channel, $subject, &$timer, &$consumerTag) { |
|
| 70 | 1 | if (!$subject->isDisposed()) { |
|
| 71 | 1 | return; |
|
| 72 | } |
||
| 73 | |||
| 74 | 1 | $this->cancelSubscription( |
|
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
React\Promise\PromiseInterface as the method done() does only exist in the following implementations of said interface: React\Promise\FulfilledPromise, React\Promise\LazyPromise, React\Promise\Promise, React\Promise\RejectedPromise.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 75 | 1 | $timer, |
|
| 76 | 1 | $channel, |
|
| 77 | 1 | $consumerTag |
|
| 78 | 1 | )->done([$subject, 'onComplete'], $this->onError($subject, $timer)); |
|
| 79 | 3 | }); |
|
| 80 | 3 | $channel->consume( |
|
|
0 ignored issues
–
show
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
Loading history...
|
|||
| 81 | 3 | function (BunnyMessage $message, Channel $channel) use ($subject, &$timer, &$consumerTag) { |
|
| 82 | 2 | if ($subject->isDisposed()) { |
|
| 83 | 1 | $channel->nack($message); |
|
| 84 | 1 | $this->cancelSubscription( |
|
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
React\Promise\PromiseInterface as the method done() does only exist in the following implementations of said interface: React\Promise\FulfilledPromise, React\Promise\LazyPromise, React\Promise\Promise, React\Promise\RejectedPromise.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 85 | 1 | $timer, |
|
|
0 ignored issues
–
show
$timer is of type object<React\EventLoop\Timer\TimerInterface>, but the function expects a object<React\EventLoop\TimerInterface>.
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...
|
|||
| 86 | 1 | $channel, |
|
| 87 | 1 | $consumerTag |
|
| 88 | 1 | )->done([$subject, 'onComplete'], $this->onError($subject, $timer)); |
|
|
0 ignored issues
–
show
$timer is of type object<React\EventLoop\Timer\TimerInterface>, but the function expects a object<React\EventLoop\TimerInterface>.
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...
|
|||
| 89 | |||
| 90 | 1 | return; |
|
| 91 | } |
||
| 92 | |||
| 93 | 1 | $subject->onNext(new Message($message, $channel)); |
|
| 94 | 3 | }, |
|
| 95 | 3 | ...$consumeArgs |
|
|
0 ignored issues
–
show
$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...
|
|||
| 96 | 3 | )->then(function (MethodBasicConsumeOkFrame $response) use (&$consumerTag) { |
|
| 97 | 2 | $consumerTag = $response->consumerTag; |
|
| 98 | 3 | })->done(null, $this->onError($subject, $timer)); |
|
|
0 ignored issues
–
show
$timer is of type object<React\EventLoop\Timer\TimerInterface>, but the function expects a object<React\EventLoop\TimerInterface>.
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...
|
|||
| 99 | 4 | })->done(null, [$subject, 'onError']); |
|
| 100 | |||
| 101 | 4 | return $subject; |
|
| 102 | } |
||
| 103 | |||
| 104 | 2 | private function cancelSubscription(TimerInterface $timer, Channel $channel, string $consumerTag): PromiseInterface |
|
| 105 | { |
||
| 106 | 2 | $this->loop->cancelTimer($timer); |
|
| 107 | |||
| 108 | 2 | return $channel->cancel($consumerTag)->then(function () use ($channel) { |
|
|
0 ignored issues
–
show
The method
then does only exist in React\Promise\PromiseInterface, but not in Bunny\Protocol\MethodBasicCancelOkFrame.
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
Loading history...
|
|||
| 109 | 2 | return $channel->close(); |
|
| 110 | 2 | }); |
|
| 111 | } |
||
| 112 | |||
| 113 | private function onError(Subject $subject, TimerInterface $timer): callable |
||
| 114 | { |
||
| 115 | 3 | return function (Throwable $et) use ($subject, $timer) { |
|
| 116 | 1 | $this->loop->cancelTimer($timer); |
|
| 117 | 1 | $subject->onError($et); |
|
| 118 | 3 | }; |
|
| 119 | } |
||
| 120 | } |
||
| 121 |
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: