Passed
Pull Request — master (#9)
by Nicolas
03:16
created

AbstractConsumer::setMessageProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $messageProvider.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
22
    private
23
        $client,
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $client.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
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($this->client->getQueue($this->workerContext->queue));
43
    }
44
45
    protected function getBaseStack()
46
    {
47
        $stack = (new Stack\Builder())
48
            ->push('Swarrot\Processor\SignalHandler\SignalHandlerProcessor', $this->logger)
49
            ->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor', $this->logger)
50
        ;
51
52
        return $stack;
53
    }
54
55
    protected function getSwarrotConsumer(Stack\Builder $stack)
56
    {
57
        return new SwarrotConsumer(
58
            $this->messageProvider,
59
            $stack->resolve($this->processor),
60
            null,
61
            $this->logger
62
        );
63
    }
64
}
65