Conditions | 15 |
Paths | 16384 |
Total Lines | 77 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
30 | public static function encode(array $properties) |
||
31 | { |
||
32 | $flags = 0; |
||
33 | $payload = ''; |
||
34 | |||
35 | if (array_key_exists('content-type', $properties)) { |
||
36 | $flags |= 32768; |
||
37 | $payload .= Value\ShortStringValue::encode($properties['content-type']); |
||
38 | } |
||
39 | |||
40 | if (array_key_exists('content-encoding', $properties)) { |
||
41 | $flags |= 16384; |
||
42 | $payload .= Value\ShortStringValue::encode($properties['content-encoding']); |
||
43 | } |
||
44 | |||
45 | if (array_key_exists('headers', $properties)) { |
||
46 | $flags |= 8192; |
||
47 | $payload .= Value\TableValue::encode($properties['headers']); |
||
48 | } |
||
49 | |||
50 | if (array_key_exists('delivery-mode', $properties)) { |
||
51 | $flags |= 4096; |
||
52 | $payload .= Value\OctetValue::encode($properties['delivery-mode']); |
||
53 | } |
||
54 | |||
55 | if (array_key_exists('priority', $properties)) { |
||
56 | $flags |= 2048; |
||
57 | $payload .= Value\OctetValue::encode($properties['priority']); |
||
58 | } |
||
59 | |||
60 | if (array_key_exists('correlation-id', $properties)) { |
||
61 | $flags |= 1024; |
||
62 | $payload .= Value\ShortStringValue::encode($properties['correlation-id']); |
||
63 | } |
||
64 | |||
65 | if (array_key_exists('reply-to', $properties)) { |
||
66 | $flags |= 512; |
||
67 | $payload .= Value\ShortStringValue::encode($properties['reply-to']); |
||
68 | } |
||
69 | |||
70 | if (array_key_exists('expiration', $properties)) { |
||
71 | $flags |= 256; |
||
72 | $payload .= Value\ShortStringValue::encode($properties['expiration']); |
||
73 | } |
||
74 | |||
75 | if (array_key_exists('message-id', $properties)) { |
||
76 | $flags |= 128; |
||
77 | $payload .= Value\ShortStringValue::encode($properties['message-id']); |
||
78 | } |
||
79 | |||
80 | if (array_key_exists('timestamp', $properties)) { |
||
81 | $flags |= 64; |
||
82 | $payload .= Value\LongLongValue::encode($properties['timestamp']); |
||
83 | } |
||
84 | |||
85 | if (array_key_exists('type', $properties)) { |
||
86 | $flags |= 32; |
||
87 | $payload .= Value\ShortStringValue::encode($properties['type']); |
||
88 | } |
||
89 | |||
90 | if (array_key_exists('user-id', $properties)) { |
||
91 | $flags |= 16; |
||
92 | $payload .= Value\ShortStringValue::encode($properties['user-id']); |
||
93 | } |
||
94 | |||
95 | if (array_key_exists('app-id', $properties)) { |
||
96 | $flags |= 8; |
||
97 | $payload .= Value\ShortStringValue::encode($properties['app-id']); |
||
98 | } |
||
99 | |||
100 | if (array_key_exists('reserved', $properties)) { |
||
101 | $flags |= 4; |
||
102 | $payload .= Value\ShortStringValue::encode($properties['reserved']); |
||
103 | } |
||
104 | |||
105 | return Value\ShortValue::encode($flags).$payload; |
||
106 | } |
||
107 | |||
177 |