AbstractStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 72.21%

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3
ccs 13
cts 18
cp 0.7221
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createRetryMessage() 0 28 2
1
<?php
2
3
namespace TreeHouse\Queue\Processor\Retry;
4
5
use TreeHouse\Queue\Amqp\EnvelopeInterface;
6
use TreeHouse\Queue\Message\Message;
7
use TreeHouse\Queue\Message\MessageProperties;
8
9
abstract class AbstractStrategy implements RetryStrategyInterface
10
{
11
    /**
12
     * Creates a new message to retry.
13
     *
14
     * @param EnvelopeInterface $envelope
15
     * @param int               $attempt
16
     * @param \Exception        $exception
17
     *
18
     * @return Message
19
     */
20 2
    protected function createRetryMessage(EnvelopeInterface $envelope, $attempt, \Exception $exception = null)
21
    {
22 2
        $headers = $envelope->getHeaders();
23 2
        $headers[RetryProcessor::PROPERTY_KEY] = $attempt;
24
25 2
        if ($exception) {
26
            $headers['x-exception'] = [
27
                'message' => $exception->getMessage(),
28
                'type' => get_class($exception),
29
                'file' => $exception->getFile(),
30
                'line' => $exception->getLine(),
31
            ];
32
        }
33
34 2
        $properties = new MessageProperties([
35 2
            MessageProperties::KEY_CONTENT_TYPE => $envelope->getContentType(),
36 2
            MessageProperties::KEY_DELIVERY_MODE => $envelope->getDeliveryMode(),
37 2
            MessageProperties::KEY_HEADERS => $headers,
38 2
            MessageProperties::KEY_PRIORITY => $envelope->getPriority(),
39
        ]);
40
41 2
        return new Message(
42 2
            $envelope->getBody(),
43
            $properties,
44 2
            $envelope->getDeliveryTag(),
45 2
            $envelope->getRoutingKey()
46
        );
47
    }
48
}
49