Test Failed
Pull Request — master (#9)
by Nicolas
06:10
created

ProcessorInterfaceAdapter::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
rs 9.0856
ccs 0
cts 17
cp 0
cc 2
eloc 11
nc 2
nop 2
crap 6
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