Conditions | 7 |
Paths | 24 |
Total Lines | 55 |
Code Lines | 38 |
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 |
||
127 | protected function processServerInfo(Buffer $buffer) |
||
128 | { |
||
129 | // Set the result to a new result instance |
||
130 | $result = new Result(); |
||
131 | |||
132 | $protocol_version = $buffer->readInt8(); |
||
133 | $result->add('protocol_version', $protocol_version); |
||
134 | |||
135 | switch ($protocol_version) { |
||
136 | case 4: |
||
137 | $num_grfs = $buffer->readInt8(); #number of grfs |
||
138 | $result->add('num_grfs', $num_grfs); |
||
139 | //$buffer->skip ($num_grfs * 20); #skip grfs id and md5 hash |
||
140 | |||
141 | for ($i=0; $i<$num_grfs; $i++) { |
||
142 | $result->add('grfs_'.$i.'_ID', strtoupper(bin2hex($buffer->read(4)))); |
||
143 | $result->add('grfs_'.$i.'_MD5', strtoupper(bin2hex($buffer->read(16)))); |
||
144 | } |
||
145 | // No break, cascades all the down even if case is meet |
||
146 | case 3: |
||
147 | $result->add('game_date', $buffer->readInt32()); |
||
148 | $result->add('start_date', $buffer->readInt32()); |
||
149 | // Cascades all the way down even if case is meet |
||
150 | case 2: |
||
151 | $result->add('companies_max', $buffer->readInt8()); |
||
152 | $result->add('companies_on', $buffer->readInt8()); |
||
153 | $result->add('spectators_max', $buffer->readInt8()); |
||
154 | // Cascades all the way down even if case is meet |
||
155 | case 1: |
||
156 | $result->add('hostname', $buffer->readString()); |
||
157 | $result->add('version', $buffer->readString()); |
||
158 | |||
159 | $language = $buffer->readInt8(); |
||
160 | $result->add('language', $language); |
||
161 | $result->add('language_icon', '//media.openttd.org/images/server/'.$language.'_lang.gif'); |
||
162 | |||
163 | $result->add('password', $buffer->readInt8()); |
||
164 | $result->add('max_clients', $buffer->readInt8()); |
||
165 | $result->add('clients', $buffer->readInt8()); |
||
166 | $result->add('spectators', $buffer->readInt8()); |
||
167 | if ($protocol_version < 3) { |
||
168 | $days = ( 365 * 1920 + 1920 / 4 - 1920 / 100 + 1920 / 400 ); |
||
169 | $result->add('game_date', $buffer->readInt16() + $days); |
||
170 | $result->add('start_date', $buffer->readInt16() + $days); |
||
171 | } |
||
172 | $result->add('map', $buffer->readString()); |
||
173 | $result->add('map_width', $buffer->readInt16()); |
||
174 | $result->add('map_height', $buffer->readInt16()); |
||
175 | $result->add('map_type', $buffer->readInt8()); |
||
176 | $result->add('dedicated', $buffer->readInt8()); |
||
177 | // Cascades all the way down even if case is meet |
||
178 | } |
||
179 | unset($buffer); |
||
180 | |||
181 | return $result->fetch(); |
||
182 | } |
||
184 |