Completed
Push — master ( 613d98...fa04c9 )
by Rémi
20:40
created

StopOnExceptionHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Burrow\Handler;
4
5
use Burrow\ConsumeOptions;
6
use Burrow\Message;
7
use Burrow\QueueHandler;
8
use Psr\Log\LoggerAwareInterface;
9
use Psr\Log\LoggerAwareTrait;
10
use Psr\Log\NullLogger;
11
12 View Code Duplication
class StopOnExceptionHandler implements QueueHandler, LoggerAwareInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    use LoggerAwareTrait;
15
16
    /** @var QueueHandler */
17
    private $handler;
18
19
    /**
20
     * AckHandler constructor.
21
     *
22
     * @param QueueHandler $handler
23
     */
24
    public function __construct(QueueHandler $handler)
25
    {
26
        $this->handler = $handler;
27
28
        $this->logger = new NullLogger();
29
    }
30
31
    /**
32
     * Handle a message.
33
     *
34
     * @param Message $message
35
     *
36
     * @return bool
37
     */
38
    public function handle(Message $message)
39
    {
40
        try {
41
            $this->handler->handle($message);
42
            return self::CONTINUE_CONSUMING;
43
        } catch (\Exception $e) {
44
            $this->logger->error($e);
45
            return self::STOP_CONSUMING;
46
        }
47
    }
48
49
    /**
50
     * Modify and return the options for consumption.
51
     *
52
     * @param ConsumeOptions $options
53
     *
54
     * @return ConsumeOptions
55
     */
56
    public function options(ConsumeOptions $options)
57
    {
58
        return $this->handler->options($options);
59
    }
60
}
61