Completed
Pull Request — master (#1)
by Sergey
04:51
created

Header::encode()   F

Complexity

Conditions 15
Paths 16384

Size

Total Lines 80
Code Lines 48

Duplication

Lines 44
Ratio 55 %

Importance

Changes 0
Metric Value
dl 44
loc 80
rs 2.0879
c 0
b 0
f 0
cc 15
eloc 48
nc 16384
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * This file is automatically generated.
4
 */
5
6
namespace ButterAMQP\AMQP091\Framing;
7
8
use ButterAMQP\Value;
9
10
/**
11
 * @codeCoverageIgnore
12
 */
13
class Header extends Frame
14
{
15
    /**
16
     * @var int
17
     */
18
    private $classId;
19
20
    /**
21
     * @var int
22
     */
23
    private $weight;
24
25
    /**
26
     * @var int
27
     */
28
    private $size;
29
30
    /**
31
     * @var array
32
     */
33
    private $properties = [];
34
35
    /**
36
     * @param int   $channel
37
     * @param int   $classId
38
     * @param int   $weight
39
     * @param int   $size
40
     * @param array $properties
41
     */
42
    public function __construct($channel, $classId, $weight, $size, array $properties = [])
43
    {
44
        $this->classId = $classId;
45
        $this->weight = $weight;
46
        $this->size = $size;
47
        $this->properties = $properties;
48
49
        parent::__construct($channel);
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function getClassId()
56
    {
57
        return $this->classId;
58
    }
59
60
    /**
61
     * @return int
62
     */
63
    public function getWeight()
64
    {
65
        return $this->weight;
66
    }
67
68
    /**
69
     * @return int
70
     */
71
    public function getSize()
72
    {
73
        return $this->size;
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getProperties()
80
    {
81
        return $this->properties;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function encode()
88
    {
89
        $flags = 0;
90
        $payload = '';
91
92 View Code Duplication
        if (array_key_exists('content-type', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
93
            $flags |= 32768;
94
            $payload .= Value\ShortStringValue::encode($this->properties['content-type']);
95
        }
96
97 View Code Duplication
        if (array_key_exists('content-encoding', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
98
            $flags |= 16384;
99
            $payload .= Value\ShortStringValue::encode($this->properties['content-encoding']);
100
        }
101
102
        if (array_key_exists('headers', $this->properties)) {
103
            $flags |= 8192;
104
            $payload .= Value\TableValue::encode($this->properties['headers']);
105
        }
106
107 View Code Duplication
        if (array_key_exists('delivery-mode', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
108
            $flags |= 4096;
109
            $payload .= Value\OctetValue::encode($this->properties['delivery-mode']);
110
        }
111
112 View Code Duplication
        if (array_key_exists('priority', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
113
            $flags |= 2048;
114
            $payload .= Value\OctetValue::encode($this->properties['priority']);
115
        }
116
117 View Code Duplication
        if (array_key_exists('correlation-id', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
118
            $flags |= 1024;
119
            $payload .= Value\ShortStringValue::encode($this->properties['correlation-id']);
120
        }
121
122 View Code Duplication
        if (array_key_exists('reply-to', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
123
            $flags |= 512;
124
            $payload .= Value\ShortStringValue::encode($this->properties['reply-to']);
125
        }
126
127 View Code Duplication
        if (array_key_exists('expiration', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
128
            $flags |= 256;
129
            $payload .= Value\ShortStringValue::encode($this->properties['expiration']);
130
        }
131
132 View Code Duplication
        if (array_key_exists('message-id', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
133
            $flags |= 128;
134
            $payload .= Value\ShortStringValue::encode($this->properties['message-id']);
135
        }
136
137
        if (array_key_exists('timestamp', $this->properties)) {
138
            $flags |= 64;
139
            $payload .= Value\LongLongValue::encode($this->properties['timestamp']);
140
        }
141
142
        if (array_key_exists('type', $this->properties)) {
143
            $flags |= 32;
144
            $payload .= Value\ShortStringValue::encode($this->properties['type']);
145
        }
146
147 View Code Duplication
        if (array_key_exists('user-id', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
148
            $flags |= 16;
149
            $payload .= Value\ShortStringValue::encode($this->properties['user-id']);
150
        }
151
152 View Code Duplication
        if (array_key_exists('app-id', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
153
            $flags |= 8;
154
            $payload .= Value\ShortStringValue::encode($this->properties['app-id']);
155
        }
156
157 View Code Duplication
        if (array_key_exists('reserved', $this->properties)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
158
            $flags |= 4;
159
            $payload .= Value\ShortStringValue::encode($this->properties['reserved']);
160
        }
161
162
        $data = pack('nnJn', $this->classId, $this->weight, $this->size, $flags).
163
            $payload;
164
165
        return "\x02".pack('nN', $this->channel, strlen($data)).$data."\xCE";
166
    }
167
}
168