Passed
Pull Request — master (#7)
by Nicolas
02:59
created

InMemoryJson   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 26.83 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 11
loc 41
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 4 1
A getRoutingKeyFromHeader() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    public function getDecodedBody()
17
    {
18
        return $this->body;
19
    }
20
    
21
    public function getAttributes()
22
    {
23
        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
        
36
    }
37
    
38 View Code Duplication
    public function getRoutingKeyFromHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $headers = $this->getHeaders();
41
        
42
        if(! array_key_exists('routing_key', $headers))
43
        {
44
            return null;
45
        }
46
        
47
        return $headers['routing_key'];
48
    }
49
}
50