Completed
Pull Request — master (#24)
by Nicolas
02:34
created

AbstractConsumer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 10.71%

Importance

Changes 0
Metric Value
dl 0
loc 53
c 0
b 0
f 0
wmc 5
lcom 1
cbo 7
ccs 3
cts 28
cp 0.1071
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A consume() 0 7 1
A setMessageProvider() 0 7 1
A getBaseStack() 0 9 1
A getSwarrotConsumer() 0 9 1
1
<?php
2
3
namespace Puzzle\AMQP\Consumers;
4
5
use Puzzle\AMQP\Consumer;
6
use Swarrot\Broker\MessageProvider\PeclPackageMessageProvider;
7
use Swarrot\Consumer as SwarrotConsumer;
8
use Swarrot\Processor\Stack;
9
use Swarrot\Processor\ProcessorInterface;
10
use Psr\Log\NullLogger;
11
use Psr\Log\LoggerAwareTrait;
12
use Puzzle\AMQP\Client;
13
use Puzzle\AMQP\Workers\WorkerContext;
14
15
abstract class AbstractConsumer implements Consumer
16
{
17
    use LoggerAwareTrait;
18
19
    protected
20
        $messageProvider;
21
22
    private
23
        $client,
24
        $processor,
25
        $workerContext;
26
27 4
    public function __construct()
28
    {
29 4
        $this->logger = new NullLogger();
30 4
    }
31
32
    public function consume(ProcessorInterface $processor, Client $client, WorkerContext $workerContext)
33
    {
34
        $this->processor = $processor;
35
        $this->client = $client;
36
        $this->workerContext = $workerContext;
37
        $this->setMessageProvider();
38
    }
39
40
    private function setMessageProvider()
41
    {
42
        $this->messageProvider = new PeclPackageMessageProvider(
43
            $this->client->getQueue(
44
                $this->workerContext->getQueue()
45
        ));
46
    }
47
48
    protected function getBaseStack()
49
    {
50
        $stack = (new Stack\Builder())
51
            ->push('Swarrot\Processor\SignalHandler\SignalHandlerProcessor', $this->logger)
52
            ->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor', $this->logger)
53
        ;
54
55
        return $stack;
56
    }
57
58
    protected function getSwarrotConsumer(Stack\Builder $stack)
59
    {
60
        return new SwarrotConsumer(
61
            $this->messageProvider,
62
            $stack->resolve($this->processor),
63
            null,
64
            $this->logger
65
        );
66
    }
67
}
68