Completed
Push — master ( 046bb8...55f246 )
by Peter
9s
created

DeprioritizeStrategy::createRetryMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
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