Issues (30)

examples/04-stomp-consumer.php (4 issues)

1
<?php
2
/**
3
 * See http://www.rabbitmq.com/stomp.html for more infos.
4
 * Run with rabbit stomp plugin.
5
 *
6
 * You must enable the plugin
7
 *   `rabbitmq-plugins enable rabbitmq_stomp`
8
 * You need to create rabbit user (stompUser, stompPass)
9
 *   Guest user have security restriction. See https://github.com/stomp-php/stomp-php/issues/105
10
 *
11
 * This example is the consumer part.
12
 * It print the message body
13
 * if the message body is "wrong" the message will be nack
14
 * else ack all message
15
 */
16
require_once __DIR__.'/../vendor/autoload.php';
17
18
use Swarrot\Broker\Message;
19
use Swarrot\Broker\MessageProvider\StatefulStompMessageProvider;
0 ignored issues
show
The type Swarrot\Broker\MessagePr...fulStompMessageProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Swarrot\Consumer;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Consumer. Consider defining an alias.

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...
21
use Swarrot\Processor\Callback\CallbackProcessor;
22
23
$client = new \Stomp\Client('tcp://localhost:61613');
0 ignored issues
show
The type Stomp\Client was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
$client->setLogin('stompUser', 'stompPass');
25
$client->setVhostname('/');
26
$client->connect();
27
28
$stompMessageProvider = new StatefulStompMessageProvider($client, '/queue/stomp_queue');
29
30
$processor = new CallbackProcessor(function (Message $message, array $options) use ($stompMessageProvider) {
0 ignored issues
show
The parameter $options is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
$processor = new CallbackProcessor(function (Message $message, /** @scrutinizer ignore-unused */ array $options) use ($stompMessageProvider) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    $body = $message->getBody();
32
    if ('wrong' == $body) {
33
        echo "$body NACK\r\n";
34
        $stompMessageProvider->nack($message);
35
36
        return;
37
    }
38
    echo "$body\r\n";
39
    $stompMessageProvider->ack($message);
40
});
41
42
$consumer = new Consumer($stompMessageProvider, $processor);
43
44
$consumer->consume([]);
45