Conditions | 66 |
Paths | 16435 |
Total Lines | 373 |
Code Lines | 266 |
Lines | 196 |
Ratio | 52.55 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | public function serialize(OutgoingFrame $frame) |
||
34 | { |
||
35 | if ($frame instanceof HeartbeatFrame) { |
||
36 | return "\x08\x00\x00\x00\x00\x00\x00\xce"; |
||
37 | } |
||
38 | if ($frame instanceof BodyFrame) { |
||
39 | return "\x03" . \pack('nN', $frame->frameChannelId, \strlen($frame->content)) . $frame->content . "\xce"; |
||
40 | } |
||
41 | if ($frame instanceof Connection\ConnectionStartOkFrame) { |
||
42 | $payload = "\x00\x0a\x00\x0b" |
||
43 | . $this->tableSerializer->serialize($frame->clientProperties) |
||
44 | . $this->serializeShortString($frame->mechanism) |
||
|
|||
45 | . $this->serializeLongString($frame->response) |
||
46 | . $this->serializeShortString($frame->locale); |
||
47 | |||
48 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
49 | } |
||
50 | if ($frame instanceof Connection\ConnectionSecureOkFrame) { |
||
51 | $payload = "\x00\x0a\x00\x15" |
||
52 | . $this->serializeLongString($frame->response); |
||
53 | |||
54 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
55 | } |
||
56 | if ($frame instanceof Connection\ConnectionTuneOkFrame) { |
||
57 | $payload = "\x00\x0a\x00\x1f" |
||
58 | . \pack('nNn', $frame->channelMax, $frame->frameMax, $frame->heartbeat); |
||
59 | |||
60 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
61 | } |
||
62 | if ($frame instanceof Connection\ConnectionOpenFrame) { |
||
63 | $payload = "\x00\x0a\x00\x28" |
||
64 | . $this->serializeShortString($frame->virtualHost) |
||
65 | . $this->serializeShortString($frame->capabilities) |
||
66 | . ($frame->insist ? "\x01" : "\x00"); |
||
67 | |||
68 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
69 | } |
||
70 | if ($frame instanceof Connection\ConnectionCloseFrame) { |
||
71 | $payload = "\x00\x0a\x00\x32" |
||
72 | . \pack('n', $frame->replyCode) |
||
73 | . $this->serializeShortString($frame->replyText) |
||
74 | . \pack('nn', $frame->classId, $frame->methodId); |
||
75 | |||
76 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
77 | } |
||
78 | if ($frame instanceof Connection\ConnectionCloseOkFrame) { |
||
79 | return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x0a\x00\x33\xce"; |
||
80 | } |
||
81 | if ($frame instanceof Channel\ChannelOpenFrame) { |
||
82 | $payload = "\x00\x14\x00\x0a" |
||
83 | . $this->serializeShortString($frame->outOfBand); |
||
84 | |||
85 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
86 | } |
||
87 | View Code Duplication | if ($frame instanceof Channel\ChannelFlowFrame) { |
|
88 | $payload = "\x00\x14\x00\x14" |
||
89 | . ($frame->active ? "\x01" : "\x00"); |
||
90 | |||
91 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
92 | } |
||
93 | View Code Duplication | if ($frame instanceof Channel\ChannelFlowOkFrame) { |
|
94 | $payload = "\x00\x14\x00\x15" |
||
95 | . ($frame->active ? "\x01" : "\x00"); |
||
96 | |||
97 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
98 | } |
||
99 | if ($frame instanceof Channel\ChannelCloseFrame) { |
||
100 | $payload = "\x00\x14\x00\x28" |
||
101 | . \pack('n', $frame->replyCode) |
||
102 | . $this->serializeShortString($frame->replyText) |
||
103 | . \pack('nn', $frame->classId, $frame->methodId); |
||
104 | |||
105 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
106 | } |
||
107 | if ($frame instanceof Channel\ChannelCloseOkFrame) { |
||
108 | return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x14\x00\x29\xce"; |
||
109 | } |
||
110 | if ($frame instanceof Access\AccessRequestFrame) { |
||
111 | $payload = "\x00\x1e\x00\x0a" |
||
112 | . $this->serializeShortString($frame->realm) |
||
113 | . \chr( |
||
114 | $frame->exclusive |
||
115 | | $frame->passive << 1 |
||
116 | | $frame->active << 2 |
||
117 | | $frame->write << 3 |
||
118 | | $frame->read << 4 |
||
119 | ); |
||
120 | |||
121 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
122 | } |
||
123 | View Code Duplication | if ($frame instanceof Exchange\ExchangeDeclareFrame) { |
|
124 | $payload = "\x00\x28\x00\x0a" |
||
125 | . \pack('n', $frame->reserved1) |
||
126 | . $this->serializeShortString($frame->exchange) |
||
127 | . $this->serializeShortString($frame->type) |
||
128 | . \chr( |
||
129 | $frame->passive |
||
130 | | $frame->durable << 1 |
||
131 | | $frame->autoDelete << 2 |
||
132 | | $frame->internal << 3 |
||
133 | | $frame->nowait << 4 |
||
134 | ) |
||
135 | . $this->tableSerializer->serialize($frame->arguments); |
||
136 | |||
137 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
138 | } |
||
139 | View Code Duplication | if ($frame instanceof Exchange\ExchangeDeleteFrame) { |
|
140 | $payload = "\x00\x28\x00\x14" |
||
141 | . \pack('n', $frame->reserved1) |
||
142 | . $this->serializeShortString($frame->exchange) |
||
143 | . \chr( |
||
144 | $frame->ifUnused |
||
145 | | $frame->nowait << 1 |
||
146 | ); |
||
147 | |||
148 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
149 | } |
||
150 | View Code Duplication | if ($frame instanceof Exchange\ExchangeBindFrame) { |
|
151 | $payload = "\x00\x28\x00\x1e" |
||
152 | . \pack('n', $frame->reserved1) |
||
153 | . $this->serializeShortString($frame->destination) |
||
154 | . $this->serializeShortString($frame->source) |
||
155 | . $this->serializeShortString($frame->routingKey) |
||
156 | . ($frame->nowait ? "\x01" : "\x00") |
||
157 | . $this->tableSerializer->serialize($frame->arguments); |
||
158 | |||
159 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
160 | } |
||
161 | View Code Duplication | if ($frame instanceof Exchange\ExchangeUnbindFrame) { |
|
162 | $payload = "\x00\x28\x00\x28" |
||
163 | . \pack('n', $frame->reserved1) |
||
164 | . $this->serializeShortString($frame->destination) |
||
165 | . $this->serializeShortString($frame->source) |
||
166 | . $this->serializeShortString($frame->routingKey) |
||
167 | . ($frame->nowait ? "\x01" : "\x00") |
||
168 | . $this->tableSerializer->serialize($frame->arguments); |
||
169 | |||
170 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
171 | } |
||
172 | View Code Duplication | if ($frame instanceof Queue\QueueDeclareFrame) { |
|
173 | $payload = "\x00\x32\x00\x0a" |
||
174 | . \pack('n', $frame->reserved1) |
||
175 | . $this->serializeShortString($frame->queue) |
||
176 | . \chr( |
||
177 | $frame->passive |
||
178 | | $frame->durable << 1 |
||
179 | | $frame->exclusive << 2 |
||
180 | | $frame->autoDelete << 3 |
||
181 | | $frame->nowait << 4 |
||
182 | ) |
||
183 | . $this->tableSerializer->serialize($frame->arguments); |
||
184 | |||
185 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
186 | } |
||
187 | View Code Duplication | if ($frame instanceof Queue\QueueBindFrame) { |
|
188 | $payload = "\x00\x32\x00\x14" |
||
189 | . \pack('n', $frame->reserved1) |
||
190 | . $this->serializeShortString($frame->queue) |
||
191 | . $this->serializeShortString($frame->exchange) |
||
192 | . $this->serializeShortString($frame->routingKey) |
||
193 | . ($frame->nowait ? "\x01" : "\x00") |
||
194 | . $this->tableSerializer->serialize($frame->arguments); |
||
195 | |||
196 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
197 | } |
||
198 | View Code Duplication | if ($frame instanceof Queue\QueuePurgeFrame) { |
|
199 | $payload = "\x00\x32\x00\x1e" |
||
200 | . \pack('n', $frame->reserved1) |
||
201 | . $this->serializeShortString($frame->queue) |
||
202 | . ($frame->nowait ? "\x01" : "\x00"); |
||
203 | |||
204 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
205 | } |
||
206 | View Code Duplication | if ($frame instanceof Queue\QueueDeleteFrame) { |
|
207 | $payload = "\x00\x32\x00\x28" |
||
208 | . \pack('n', $frame->reserved1) |
||
209 | . $this->serializeShortString($frame->queue) |
||
210 | . \chr( |
||
211 | $frame->ifUnused |
||
212 | | $frame->ifEmpty << 1 |
||
213 | | $frame->nowait << 2 |
||
214 | ); |
||
215 | |||
216 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
217 | } |
||
218 | View Code Duplication | if ($frame instanceof Queue\QueueUnbindFrame) { |
|
219 | $payload = "\x00\x32\x00\x32" |
||
220 | . \pack('n', $frame->reserved1) |
||
221 | . $this->serializeShortString($frame->queue) |
||
222 | . $this->serializeShortString($frame->exchange) |
||
223 | . $this->serializeShortString($frame->routingKey) |
||
224 | . $this->tableSerializer->serialize($frame->arguments); |
||
225 | |||
226 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
227 | } |
||
228 | if ($frame instanceof Basic\BasicHeaderFrame) { |
||
229 | $flags = 0; |
||
230 | $properties = ''; |
||
231 | |||
232 | if (null !== $frame->contentType) { |
||
233 | $flags |= 32768; |
||
234 | $properties .= $this->serializeShortString($frame->contentType); |
||
235 | } |
||
236 | |||
237 | if (null !== $frame->contentEncoding) { |
||
238 | $flags |= 16384; |
||
239 | $properties .= $this->serializeShortString($frame->contentEncoding); |
||
240 | } |
||
241 | |||
242 | if (null !== $frame->headers) { |
||
243 | $flags |= 8192; |
||
244 | $properties .= $this->tableSerializer->serialize($frame->headers); |
||
245 | } |
||
246 | |||
247 | View Code Duplication | if (null !== $frame->deliveryMode) { |
|
248 | $flags |= 4096; |
||
249 | $properties .= \pack('c', $frame->deliveryMode); |
||
250 | } |
||
251 | |||
252 | View Code Duplication | if (null !== $frame->priority) { |
|
253 | $flags |= 2048; |
||
254 | $properties .= \pack('c', $frame->priority); |
||
255 | } |
||
256 | |||
257 | if (null !== $frame->correlationId) { |
||
258 | $flags |= 1024; |
||
259 | $properties .= $this->serializeShortString($frame->correlationId); |
||
260 | } |
||
261 | |||
262 | if (null !== $frame->replyTo) { |
||
263 | $flags |= 512; |
||
264 | $properties .= $this->serializeShortString($frame->replyTo); |
||
265 | } |
||
266 | |||
267 | if (null !== $frame->expiration) { |
||
268 | $flags |= 256; |
||
269 | $properties .= $this->serializeShortString($frame->expiration); |
||
270 | } |
||
271 | |||
272 | if (null !== $frame->messageId) { |
||
273 | $flags |= 128; |
||
274 | $properties .= $this->serializeShortString($frame->messageId); |
||
275 | } |
||
276 | |||
277 | if (null !== $frame->timestamp) { |
||
278 | $flags |= 64; |
||
279 | $properties .= \pack('J', $frame->timestamp); |
||
280 | } |
||
281 | |||
282 | if (null !== $frame->type) { |
||
283 | $flags |= 32; |
||
284 | $properties .= $this->serializeShortString($frame->type); |
||
285 | } |
||
286 | |||
287 | if (null !== $frame->userId) { |
||
288 | $flags |= 16; |
||
289 | $properties .= $this->serializeShortString($frame->userId); |
||
290 | } |
||
291 | |||
292 | if (null !== $frame->appId) { |
||
293 | $flags |= 8; |
||
294 | $properties .= $this->serializeShortString($frame->appId); |
||
295 | } |
||
296 | |||
297 | if (null !== $frame->clusterId) { |
||
298 | $flags |= 4; |
||
299 | $properties .= $this->serializeShortString($frame->clusterId); |
||
300 | } |
||
301 | |||
302 | $payload = "\x00\x3c\x00\x00" |
||
303 | . \pack('Jn', $frame->contentLength, $flags) |
||
304 | . $properties; |
||
305 | |||
306 | return "\x02" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
307 | } |
||
308 | if ($frame instanceof Basic\BasicQosFrame) { |
||
309 | $payload = "\x00\x3c\x00\x0a" |
||
310 | . \pack('Nn', $frame->prefetchSize, $frame->prefetchCount) |
||
311 | . ($frame->global ? "\x01" : "\x00"); |
||
312 | |||
313 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
314 | } |
||
315 | View Code Duplication | if ($frame instanceof Basic\BasicConsumeFrame) { |
|
316 | $payload = "\x00\x3c\x00\x14" |
||
317 | . \pack('n', $frame->reserved1) |
||
318 | . $this->serializeShortString($frame->queue) |
||
319 | . $this->serializeShortString($frame->consumerTag) |
||
320 | . \chr( |
||
321 | $frame->noLocal |
||
322 | | $frame->noAck << 1 |
||
323 | | $frame->exclusive << 2 |
||
324 | | $frame->nowait << 3 |
||
325 | ) |
||
326 | . $this->tableSerializer->serialize($frame->arguments); |
||
327 | |||
328 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
329 | } |
||
330 | if ($frame instanceof Basic\BasicCancelFrame) { |
||
331 | $payload = "\x00\x3c\x00\x1e" |
||
332 | . $this->serializeShortString($frame->consumerTag) |
||
333 | . ($frame->nowait ? "\x01" : "\x00"); |
||
334 | |||
335 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
336 | } |
||
337 | View Code Duplication | if ($frame instanceof Basic\BasicPublishFrame) { |
|
338 | $payload = "\x00\x3c\x00\x28" |
||
339 | . \pack('n', $frame->reserved1) |
||
340 | . $this->serializeShortString($frame->exchange) |
||
341 | . $this->serializeShortString($frame->routingKey) |
||
342 | . \chr( |
||
343 | $frame->mandatory |
||
344 | | $frame->immediate << 1 |
||
345 | ); |
||
346 | |||
347 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
348 | } |
||
349 | View Code Duplication | if ($frame instanceof Basic\BasicGetFrame) { |
|
350 | $payload = "\x00\x3c\x00\x46" |
||
351 | . \pack('n', $frame->reserved1) |
||
352 | . $this->serializeShortString($frame->queue) |
||
353 | . ($frame->noAck ? "\x01" : "\x00"); |
||
354 | |||
355 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
356 | } |
||
357 | View Code Duplication | if ($frame instanceof Basic\BasicAckFrame) { |
|
358 | $payload = "\x00\x3c\x00\x50" |
||
359 | . \pack('J', $frame->deliveryTag) |
||
360 | . ($frame->multiple ? "\x01" : "\x00"); |
||
361 | |||
362 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
363 | } |
||
364 | View Code Duplication | if ($frame instanceof Basic\BasicRejectFrame) { |
|
365 | $payload = "\x00\x3c\x00\x5a" |
||
366 | . \pack('J', $frame->deliveryTag) |
||
367 | . ($frame->requeue ? "\x01" : "\x00"); |
||
368 | |||
369 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
370 | } |
||
371 | View Code Duplication | if ($frame instanceof Basic\BasicRecoverFrame) { |
|
372 | $payload = "\x00\x3c\x00\x6e" |
||
373 | . ($frame->requeue ? "\x01" : "\x00"); |
||
374 | |||
375 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
376 | } |
||
377 | View Code Duplication | if ($frame instanceof Basic\BasicNackFrame) { |
|
378 | $payload = "\x00\x3c\x00\x78" |
||
379 | . \pack('J', $frame->deliveryTag) |
||
380 | . \chr( |
||
381 | $frame->multiple |
||
382 | | $frame->requeue << 1 |
||
383 | ); |
||
384 | |||
385 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
386 | } |
||
387 | if ($frame instanceof Tx\TxSelectFrame) { |
||
388 | return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x0a\xce"; |
||
389 | } |
||
390 | if ($frame instanceof Tx\TxCommitFrame) { |
||
391 | return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x14\xce"; |
||
392 | } |
||
393 | if ($frame instanceof Tx\TxRollbackFrame) { |
||
394 | return "\x01" . \pack('n', $frame->frameChannelId) . "\x00\x00\x00\x04\x00\x5a\x00\x1e\xce"; |
||
395 | } |
||
396 | View Code Duplication | if ($frame instanceof Confirm\ConfirmSelectFrame) { |
|
397 | $payload = "\x00\x55\x00\x0a" |
||
398 | . ($frame->nowait ? "\x01" : "\x00"); |
||
399 | |||
400 | return "\x01" . \pack('nN', $frame->frameChannelId, \strlen($payload)) . $payload . "\xce"; |
||
401 | } |
||
402 | |||
403 | throw new AMQPProtocolException( |
||
404 | sprintf('Frame %s not implemented yet', get_class($frame))); |
||
405 | } |
||
406 | } |
||
407 |
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.