These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | require_once __DIR__.'/../vendor/autoload.php'; |
||
4 | |||
5 | use Swarrot\Broker\Message; |
||
6 | use Swarrot\Broker\PeclPackageMessageProvider; |
||
7 | use Swarrot\Consumer; |
||
8 | use Swarrot\Processor\ProcessorInterface; |
||
9 | |||
10 | class Processor implements ProcessorInterface |
||
0 ignored issues
–
show
|
|||
11 | { |
||
12 | protected $processor; |
||
13 | |||
14 | protected $num; |
||
15 | |||
16 | public function __construct($processor, $num = 1) |
||
17 | { |
||
18 | $this->processor = $processor; |
||
0 ignored issues
–
show
The property
processor does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
19 | $this->num = (int) $num; |
||
0 ignored issues
–
show
The property
num does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
Loading history...
|
|||
20 | } |
||
21 | |||
22 | public function process(Message $message, array $options) |
||
23 | { |
||
24 | printf("Start processing message #%d in processor #%d\n", $message->getId(), $this->num); |
||
25 | $return = $this->processor->process($message, $options); |
||
26 | printf("End processing message #%d in processor #%d\n", $message->getId(), $this->num); |
||
27 | |||
28 | return $return; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | class FinalProcessor implements ProcessorInterface |
||
33 | { |
||
34 | public function process(Message $message, array $options) |
||
35 | { |
||
36 | printf("Consume message #%d\n", $message->getId()); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | $connection = new \AMQPConnection(); |
||
41 | $connection->connect(); |
||
42 | $channel = new \AMQPChannel($connection); |
||
43 | $queue = new \AMQPQueue($channel); |
||
44 | $queue->setName('global'); |
||
45 | |||
46 | $messageProvider = new PeclPackageMessageProvider($queue); |
||
47 | |||
48 | $stack = (new \Swarrot\Processor\Stack\Builder()) |
||
49 | ->push('Processor', 1) |
||
50 | ->push('Processor', 2) |
||
51 | ; |
||
52 | $processor = $stack->resolve(new FinalProcessor()); |
||
53 | |||
54 | $consumer = new Consumer($messageProvider, $processor); |
||
55 | $consumer->consume(); |
||
56 |
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.