CallbackProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 87
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A mount() 0 14 1
A process() 0 3 1
A __construct() 0 3 1
A unmount() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ\Processor;
6
7
use Interop\Amqp;
8
use Psr\Log\LoggerInterface;
9
use BinaryCube\CarrotMQ\Container;
10
use BinaryCube\CarrotMQ\Entity\Queue;
11
12
use function call_user_func_array;
13
14
/**
15
 * Class CallbackProcessor
16
 */
17
class CallbackProcessor implements Processor
18
{
19
20
    /**
21
     * @var callable
22
     */
23
    protected $callback;
24
25
    /**
26
     * @var Queue
27
     */
28
    protected $queue;
29
30
    /**
31
     * @var Amqp\AmqpContext
32
     */
33
    protected $context;
34
35
    /**
36
     * @var Amqp\AmqpConsumer
37
     */
38
    protected $consumer;
39
40
    /**
41
     * @var Container
42
     */
43
    protected $container;
44
45
    /**
46
     * @var LoggerInterface
47
     */
48
    protected $logger;
49
50
    /**
51
     * Constructor.
52
     *
53
     * @param callable $callback
54
     */
55
    public function __construct(callable $callback)
56
    {
57
        $this->callback = $callback;
58
    }
59
60
    /**
61
     * @param Queue                $queue
62
     * @param Amqp\AmqpContext     $context
63
     * @param Amqp\AmqpConsumer    $consumer
64
     * @param Container|null       $container
65
     * @param LoggerInterface|null $logger
66
     *
67
     * @return $this
68
     */
69
    public function mount(
70
        Queue $queue,
71
        Amqp\AmqpContext $context,
72
        Amqp\AmqpConsumer $consumer,
73
        Container $container = null,
74
        ?LoggerInterface $logger = null
75
    ) {
76
        $this->queue     = $queue;
77
        $this->context   = $context;
78
        $this->consumer  = $consumer;
79
        $this->container = $container;
80
        $this->logger    = $logger;
81
82
        return $this;
83
    }
84
85
    /**
86
     * @return $this
87
     */
88
    public function unmount()
89
    {
90
        return $this;
91
    }
92
93
    /**
94
     * The method has to return either self::ACK, self::REJECT, self::REQUEUE, self::SELF_ACK string.
95
     *
96
     * @param Amqp\AmqpMessage $message The message
97
     * @param Amqp\AmqpContext $context The context
98
     *
99
     * @return mixed false to requeue, any other value to acknowledge
100
     */
101
    public function process(Amqp\AmqpMessage $message, Amqp\AmqpContext $context)
102
    {
103
        return call_user_func_array($this->callback, [$message, $context]);
104
    }
105
106
}
107