DeprioritizeStrategy::retry()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace TreeHouse\Queue\Processor\Retry;
4
5
use TreeHouse\Queue\Amqp\EnvelopeInterface;
6
use TreeHouse\Queue\Message\Publisher\MessagePublisherInterface;
7
8
/**
9
 * Retries the message, but with the priority decreasing with every attempt.
10
 */
11
class DeprioritizeStrategy extends AbstractStrategy
12
{
13
    /**
14
     * @var MessagePublisherInterface
15
     */
16
    protected $publisher;
17
18
    /**
19
     * @param MessagePublisherInterface $publisher
20
     */
21 1
    public function __construct(MessagePublisherInterface $publisher)
22
    {
23 1
        $this->publisher = $publisher;
24 1
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29 1
    public function retry(EnvelopeInterface $envelope, $attempt, \Exception $exception = null)
30
    {
31
        // decrease priority with every attempt
32 1
        $priority = $envelope->getPriority();
33 1
        if ($priority > 0) {
34 1
            --$priority;
35
        }
36
37 1
        $message = $this->createRetryMessage($envelope, $attempt, $exception);
38 1
        $message->setPriority($priority);
39
40 1
        return $this->publisher->publish($message);
41
    }
42
}
43