| Conditions | 12 | 
| Paths | 10 | 
| Total Lines | 33 | 
| 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 | ||
| 74 | public function firstDifference($old, $new) | ||
| 75 |     { | ||
| 76 | // loop through old and new character by character and compare | ||
| 77 | $oldLen = mb_strlen($old); | ||
| 78 | $newLen = mb_strlen($new); | ||
| 79 | |||
| 80 |         if ($oldLen === 0) { | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | $oldStripped = $this->cursor->filter($old, static::REPLACEMENT_CHAR); | ||
| 85 | $newStripped = $this->cursor->filter($new, static::REPLACEMENT_CHAR); | ||
| 86 | $lastReal = 0; | ||
| 87 | |||
| 88 |         for ($i = 0; $i < $oldLen && $i < $newLen; $i++) { | ||
| 89 |             if (mb_substr($old, $i, 1) !== mb_substr($new, $i, 1)) { | ||
| 90 | if (($i > 0) | ||
| 91 | && ((mb_substr($oldStripped, $i - 1, 1) === static::REPLACEMENT_CHAR) | ||
| 92 | || (mb_substr($newStripped, $i - 1, 1) === static::REPLACEMENT_CHAR) | ||
| 93 | ) | ||
| 94 |                 ) { | ||
| 95 | return $lastReal > 0 ? $lastReal + 1 : 0; | ||
| 96 | } | ||
| 97 | return $i; | ||
| 98 |             } elseif (mb_substr($oldStripped, $i, 1) !== static::REPLACEMENT_CHAR) { | ||
| 99 | $lastReal = $i; | ||
| 100 | } | ||
| 101 | } | ||
| 102 |         if ($i < $oldLen || $i < $newLen) { | ||
| 103 | return $i; | ||
| 104 | } | ||
| 105 | return -1; | ||
| 106 | } | ||
| 107 | } | ||
| 108 |