Test Failed
Pull Request — master (#9)
by Nicolas
03:28
created

ProcessorInterfaceAdapter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 47
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6
rs 10
ccs 0
cts 30
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A process() 0 23 2
A onWorkerProcess() 0 4 1
A onWorkerProcessed() 0 4 1
1
<?php
2
3
namespace Puzzle\AMQP\Workers;
4
5
use Swarrot\Processor\ProcessorInterface;
6
use Puzzle\Pieces\EventDispatcher\NullEventDispatcher;
7
use Puzzle\Pieces\EventDispatcher\EventDispatcherAware;
8
9
class ProcessorInterfaceAdapter implements ProcessorInterface
10
{
11
    use EventDispatcherAware;
12
    
13
    private
14
        $workerContext;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $workerContext.

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...
15
    
16
    public function __construct(WorkerContext $workerContext)
17
    {
18
        $this->workerContext = $workerContext;
19
        $this->eventDispatcher = new NullEventDispatcher();
20
    }
21
    
22
    public function process(\Swarrot\Broker\Message $message, array $options)
23
    {
24
        $message = new MessageAdapter($message);
25
        
26
        $this->workerContext->getLogger()->debug((string) $message);
27
        
28
        $this->onWorkerProcess();
29
30
        try
31
        {
32
            $processResult = $this->workerContext->getWorker()->process($message);
33
        }
34
        catch(\Exception $exception)
35
        {
36
            $this->onWorkerProcessed();
37
38
            throw $exception;
39
        }
40
        
41
        $this->onWorkerProcessed();
42
43
        return $processResult;
44
    }
45
46
    private function onWorkerProcess()
47
    {
48
        $this->eventDispatcher->dispatch('worker.process');
49
    }
50
    
51
    private function onWorkerProcessed()
52
    {
53
        $this->eventDispatcher->dispatch('worker.processed');
54
    }
55
}
56