RepostOnTimeOutProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A process() 0 21 3
1
<?php
2
3
namespace Dekalee\RedisSwarrot\Processor;
4
5
use Psr\Log\LoggerInterface;
6
use Swarrot\Broker\Message;
7
use Swarrot\Broker\MessageProvider\MessageProviderInterface;
8
use Swarrot\Processor\ProcessorInterface;
9
10
/**
11
 * Class RepostOnTimeOutProcessor
12
 */
13
class RepostOnTimeOutProcessor implements ProcessorInterface
14
{
15
    protected $processor;
16
    protected $messageProvider;
17
    protected $logger;
18
19
    /**
20
     * @param ProcessorInterface       $processor       Processor
21
     * @param MessageProviderInterface $messageProvider Message provider
22
     * @param LoggerInterface          $logger          Logger
23
     */
24
    public function __construct(ProcessorInterface $processor, MessageProviderInterface $messageProvider, LoggerInterface $logger = null)
25
    {
26
        $this->processor = $processor;
27
        $this->messageProvider = $messageProvider;
28
        $this->logger = $logger;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function process(Message $message, array $options)
35
    {
36
        $return = $this->processor->process($message, $options);
37
38
        if (false === $return) {
39
            $this->messageProvider->nack($message, true);
40
41
            $this->logger and $this->logger->info(
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
42
                sprintf(
43
                    '[Repost] A timeout occurred. Message #%d has been %s.',
44
                    $message->getId(),
45
                    'requeued'
46
                ),
47
                [
48
                    'swarrot_processor' => 'repost',
49
                ]
50
            );
51
        }
52
53
        return $return;
54
    }
55
56
}
57