| Conditions | 14 |
| Paths | 8 |
| Total Lines | 26 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 71 | private static function renderChicago($from, $to) |
||
| 72 | { |
||
| 73 | if ($from == 100 || $from % 100 === 0) { |
||
| 74 | return $to; |
||
| 75 | } else if ($from < 100) { |
||
| 76 | return $to; |
||
| 77 | } else if ($from % 100 < 10) { |
||
| 78 | return self::renderMinimal($from, $to); //Use changed part only, omitting unneeded zeros |
||
| 79 | } else if (strlen($from) == 4) { |
||
| 80 | if ($from % 1000 != $to % 1000) { |
||
| 81 | return $to; |
||
| 82 | } |
||
| 83 | return self::renderMinimal($from, $to); |
||
| 84 | } else if (strlen($from) != 4 && $from % 100 >= 10 && $from % 100 <= 99) { |
||
| 85 | $resTo = substr($to,-2); |
||
| 86 | $from_ = substr($from, 0, strlen($from) - 2); |
||
| 87 | $to_ = substr($to, 0, strlen($to) - 2); |
||
| 88 | if ($from_ != $to_ && strlen($from_) == strlen($to_)) { |
||
| 89 | for ($i = strlen($from_)-1; $i >= 0 && $to_{$i} != $from_{$i}; --$i) { |
||
| 90 | $resTo = $to{$i} . $resTo; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | return $resTo; |
||
| 94 | } |
||
| 95 | return self::renderMinimal($from, $to, 1); |
||
| 96 | } |
||
| 97 | } |