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

ProcessorInterfaceAdapter::onWorkerProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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