AmqpListener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 47
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handle() 0 12 1
1
<?php
2
3
namespace Softonic\AmqpConsumer;
4
5
use Bschmitt\Amqp\Amqp;
6
use Illuminate\Console\Command;
7
8
class AmqpListener extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'amqp:listen';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Listen AMQP messages';
23
24
    /**
25
     * @var string
26
     */
27
    protected $queue;
28
29
    /**
30
     * @var array
31
     */
32
    protected $amqpProperties;
33
34
    public function __construct(string $queue, array $amqpProperties)
35
    {
36
        parent::__construct();
37
38
        $this->queue          = $queue;
39
        $this->amqpProperties = $amqpProperties;
40
    }
41
42
    public function handle(Amqp $amqp, AmqpHandler $amqpHandler)
43
    {
44
        $amqp->consume(
45
            $this->queue,
46
            function ($message, $resolver) use ($amqpHandler) {
47
                $amqpHandler->handle($message);
48
49
                $resolver->acknowledge($message);
50
            },
51
            $this->amqpProperties
52
        );
53
    }
54
}
55