Publisher::publish()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 50
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 50
rs 9.8666
1
<?php
2
3
namespace OrderManagement\RabbitMQ;
4
5
use PhpAmqpLib\Message\AMQPMessage;
0 ignored issues
show
Bug introduced by
The type PhpAmqpLib\Message\AMQPMessage 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...
6
7
class Publisher
8
{
9
    /**
10
     * @var AbstractQueue
11
     */
12
    protected $queue;
13
14
    /**
15
     * @param QueueInterface $queue
16
     */
17
    public function __construct(QueueInterface $queue)
18
    {
19
        $this->queue = $queue;
0 ignored issues
show
Documentation Bug introduced by
$queue is of type OrderManagement\RabbitMQ\QueueInterface, but the property $queue was declared to be of type OrderManagement\RabbitMQ\AbstractQueue. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
20
    }
21
22
    public function publish($message)
0 ignored issues
show
Unused Code introduced by
The parameter $message 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

22
    public function publish(/** @scrutinizer ignore-unused */ $message)

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...
23
    {
24
        $connection = new Connection();
25
        $channel = $connection->channel();
26
27
        $channel->queue_declare(
28
            $this->queue->getName(),
29
            $this->queue->isPassive(),
30
            $this->queue->isDurable(),
31
            $this->queue->isExclusive(),
32
            $this->queue->isAutoDelete()
33
        );
34
35
        $message = new AMQPMessage(json_encode(['product_id'=>1,'product_name'=>'deneme'], JSON_UNESCAPED_SLASHES), array('delivery_mode' => 2));
36
        $channel->basic_publish($message, '', $this->queue->getName());
37
38
//        $channel->queue_declare(
39
//            $queue = RABBITMQ_QUEUE_NAME,
40
//            $passive = false,
41
//            $durable = true,
42
//            $exclusive = false,
43
//            $auto_delete = false,
44
//            $nowait = false,
45
//            $arguments = null,
46
//            $ticket = null
47
//        );
48
//
49
//        $job_id=0;
50
//        while (true)
51
//        {
52
//            $jobArray = array(
53
//                'id' => $job_id++,
54
//                'task' => 'sleep',
55
//                'sleep_period' => rand(0, 3)
56
//            );
57
//
58
//            $msg = new AMQPMessage(
59
//                json_encode($jobArray, JSON_UNESCAPED_SLASHES),
60
//                array('delivery_mode' => 2) # make message persistent
61
//            );
62
//
63
//            $channel->basic_publish($msg, '', $this->queue->getName());
64
//            print 'Job created' . PHP_EOL;
65
//            sleep(1);
66
//        }
67
68
69
70
        $channel->close();
71
        $connection->close();
72
    }
73
}
74