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

ContinueOnExceptionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Burrow\Handler;
4
5
use Burrow\ConsumeOptions;
6
use Burrow\Exception\ConsumerException;
7
use Burrow\Message;
8
use Burrow\QueueHandler;
9
use Psr\Log\LoggerAwareInterface;
10
use Psr\Log\LoggerAwareTrait;
11
use Psr\Log\NullLogger;
12
13 View Code Duplication
class ContinueOnExceptionHandler 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...
14
{
15
    use LoggerAwareTrait;
16
17
    /** @var QueueHandler */
18
    private $handler;
19
20
    /**
21
     * AckHandler constructor.
22
     *
23
     * @param QueueHandler $handler
24
     */
25
    public function __construct(QueueHandler $handler)
26
    {
27
        $this->handler = $handler;
28
29
        $this->logger = new NullLogger();
30
    }
31
32
    /**
33
     * Handle a message.
34
     *
35
     * @param Message $message
36
     *
37
     * @return bool
38
     */
39
    public function handle(Message $message)
40
    {
41
        // Beware of infinite loop!
42
        try {
43
            $this->handler->handle($message);
44
        } catch (\Exception $e) {
45
            $this->logger->error($e);
46
47
            if ($e instanceof ConsumerException) {
48
                return false;
49
            }
50
        }
51
52
        return self::CONTINUE_CONSUMING;
53
    }
54
55
    /**
56
     * Modify and return the options for consumption.
57
     *
58
     * @param ConsumeOptions $options
59
     *
60
     * @return ConsumeOptions
61
     */
62
    public function options(ConsumeOptions $options)
63
    {
64
        return $this->handler->options($options);
65
    }
66
}
67