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

AbstractConsumer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 12%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 50
ccs 3
cts 25
cp 0.12
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A consume() 0 7 1
A setMessageProvider() 0 4 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;
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