Test Failed
Pull Request — master (#29)
by Nicolas
02:57
created

ProcessorInterfaceAdapter::onWorkerProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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
use Puzzle\AMQP\Clients\Processors\MessageProcessorAware;
9
10
class ProcessorInterfaceAdapter implements ProcessorInterface
11
{
12
    use
13
        EventDispatcherAware,
14
        MessageProcessorAware;
15
    
16 1
    private
17
        $workerContext;
18 1
    
19 1
    public function __construct(WorkerContext $workerContext)
20 1
    {
21
        $this->workerContext = $workerContext;
22 1
        $this->eventDispatcher = new NullEventDispatcher();
23
    }
24 1
    
25
    public function process(\Swarrot\Broker\Message $message, array $options)
26 1
    {
27
        $message = new MessageAdapter($message);
28 1
        $message = $this->onConsume($message);
29
        
30
        $this->workerContext->getLogger()->debug((string) $message);
31
        
32 1
        $this->onWorkerProcess();
33
34 1
        try
35
        {
36
            $processResult = $this->workerContext->getWorker()->process($message);
37
        }
38
        catch(\Exception $exception)
39
        {
40
            $this->onWorkerProcessed();
41 1
42
            throw $exception;
43 1
        }
44
        
45
        $this->onWorkerProcessed();
46 1
47
        return $processResult;
48 1
    }
49 1
50
    private function onWorkerProcess()
51 1
    {
52
        $this->eventDispatcher->dispatch('worker.process');
53 1
    }
54 1
    
55
    private function onWorkerProcessed()
56
    {
57
        $this->eventDispatcher->dispatch('worker.processed');
58
    }
59
}
60