| Conditions | 11 |
| Paths | 11 |
| Total Lines | 40 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 9 | static function parseNormalError(\XMLReader $xmlReader) { |
||
| 10 | $result = array('Code' => NULL, 'Message' => NULL, 'RequestId' => NULL, 'HostId' => NULL); |
||
| 11 | while ($xmlReader->Read()) |
||
| 12 | { |
||
| 13 | if ($xmlReader->nodeType == \XMLReader::ELEMENT) |
||
| 14 | { |
||
| 15 | switch ($xmlReader->name) { |
||
| 16 | case 'Code': |
||
| 17 | $xmlReader->read(); |
||
| 18 | if ($xmlReader->nodeType == \XMLReader::TEXT) |
||
| 19 | { |
||
| 20 | $result['Code'] = $xmlReader->value; |
||
| 21 | } |
||
| 22 | break; |
||
| 23 | case 'Message': |
||
| 24 | $xmlReader->read(); |
||
| 25 | if ($xmlReader->nodeType == \XMLReader::TEXT) |
||
| 26 | { |
||
| 27 | $result['Message'] = $xmlReader->value; |
||
| 28 | } |
||
| 29 | break; |
||
| 30 | case 'RequestId': |
||
| 31 | $xmlReader->read(); |
||
| 32 | if ($xmlReader->nodeType == \XMLReader::TEXT) |
||
| 33 | { |
||
| 34 | $result['RequestId'] = $xmlReader->value; |
||
| 35 | } |
||
| 36 | break; |
||
| 37 | case 'HostId': |
||
| 38 | $xmlReader->read(); |
||
| 39 | if ($xmlReader->nodeType == \XMLReader::TEXT) |
||
| 40 | { |
||
| 41 | $result['HostId'] = $xmlReader->value; |
||
| 42 | } |
||
| 43 | break; |
||
| 44 | } |
||
| 45 | } |
||
| 46 | } |
||
| 47 | return $result; |
||
| 48 | } |
||
| 49 | } |
||
| 52 |