Completed
Push — master ( 4bf91f...d42076 )
by Nicolas
03:14
created

InMemoryJson   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 48
ccs 10
cts 22
cp 0.4545
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawBody() 0 4 1
A getDecodedBody() 0 4 1
A getAttributes() 0 4 1
A isLastRetry() 0 6 2
A applyHooks() 0 11 2
A getRoutingKeyFromHeader() 0 11 2
1
<?php
2
3
namespace Puzzle\AMQP\Messages;
4
5
use Puzzle\AMQP\ReadableMessage;
6
use Puzzle\AMQP\WritableMessage;
7
use Puzzle\AMQP\Collections\MessageHookCollection;
8
9
class InMemoryJson extends Json implements ReadableMessage, WritableMessage
10
{
11
    public function getRawBody()
12
    {
13
        return $this->getFormattedBody();
14
    }
15
16 2
    public function getDecodedBody()
17
    {
18 2
        return $this->body;
19
    }
20
21 2
    public function getAttributes()
22
    {
23 2
        return $this->packAttributes();
24
    }
25
26
    public function isLastRetry($retryOccurence = \Puzzle\AMQP\Consumers\Retry::DEFAULT_RETRY_OCCURENCE)
27
    {
28
        $retryHeader = $this->getHeader(\Puzzle\AMQP\Consumers\Retry::DEFAULT_RETRY_HEADER);
0 ignored issues
show
Bug introduced by
The method getHeader() does not exist on Puzzle\AMQP\Messages\InMemoryJson. Did you maybe mean getHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29
30
        return (!empty($retryHeader) && (int) $retryHeader === $retryOccurence);
31
    }
32
33
    public function applyHooks(MessageHookCollection $messageHookCollection)
34
    {
35
        $body = $this->body;
36
37
        foreach($messageHookCollection as $hook)
38
        {
39
            $body = $hook->process($body);
40
        }
41
42
        $this->body = $body;
43
    }
44
45 1
    public function getRoutingKeyFromHeader()
46
    {
47 1
        $headers = $this->getHeaders();
48
49 1
        if(! array_key_exists('routing_key', $headers))
50 1
        {
51 1
            return null;
52
        }
53
54 1
        return $headers['routing_key'];
55
    }
56
}
57