OutgoingPhysicalMessage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 13.25 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 11
loc 83
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A getMessageId() 0 4 1
A getHeaders() 0 4 1
A setHeader() 0 4 1
A replaceHeaders() 0 4 1
A getBody() 0 4 1
A replaceBody() 0 6 1

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
namespace PSB\Core\Transport;
3
4
5
use PSB\Core\Util\Guard;
6
7
class OutgoingPhysicalMessage
8
{
9
    /**
10
     * @var string
11
     */
12
    private $messageId;
13
14
    /**
15
     * @var array
16
     */
17
    private $headers;
18
19
    /**
20
     * @var string
21
     */
22
    private $body;
23
24
    /**
25
     * @param string $messageId
26
     * @param array  $headers
27
     * @param string $body
28
     */
29 33 View Code Duplication
    public function __construct($messageId, array $headers, $body)
30
    {
31 33
        Guard::againstNullAndEmpty('messageId', $messageId);
32 32
        Guard::againstNull('body', $body);
33
34 31
        $this->messageId = $messageId;
35 31
        $this->headers = $headers;
36 31
        $this->body = $body;
37 31
    }
38
39
    /**
40
     * @return string
41
     */
42 1
    public function getMessageId()
43
    {
44 1
        return $this->messageId;
45
    }
46
47
    /**
48
     * @return array
49
     */
50 4
    public function getHeaders()
51
    {
52 4
        return $this->headers;
53
    }
54
55
    /**
56
     * @param string $name
57
     * @param string $value
58
     */
59 2
    public function setHeader($name, $value)
60
    {
61 2
        $this->headers[$name] = $value;
62 2
    }
63
64
    /**
65
     * @param array $headers
66
     */
67 1
    public function replaceHeaders(array $headers)
68
    {
69 1
        $this->headers = $headers;
70 1
    }
71
72
    /**
73
     * @return string
74
     */
75 4
    public function getBody()
76
    {
77 4
        return $this->body;
78
    }
79
80
    /**
81
     * @param string $body
82
     */
83 2
    public function replaceBody($body)
84
    {
85 2
        Guard::againstNull('body', $body);
86
87 1
        $this->body = $body;
88 1
    }
89
}
90