| Conditions | 19 | 
| Paths | 5120 | 
| Total Lines | 90 | 
| Code Lines | 53 | 
| Lines | 6 | 
| Ratio | 6.67 % | 
| 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  | 
            ||
| 135 | public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)  | 
            ||
| 136 |     { | 
            ||
| 137 |         preg_match_all('(\r\n|\r|\n)', $from, $fromMatches); | 
            ||
| 138 |         preg_match_all('(\r\n|\r|\n)', $to, $toMatches); | 
            ||
| 139 | |||
| 140 |         if (is_string($from)) { | 
            ||
| 141 |             $from = preg_split('(\r\n|\r|\n)', $from); | 
            ||
| 142 | }  | 
            ||
| 143 | |||
| 144 |         if (is_string($to)) { | 
            ||
| 145 |             $to = preg_split('(\r\n|\r|\n)', $to); | 
            ||
| 146 | }  | 
            ||
| 147 | |||
| 148 | $start = array();  | 
            ||
| 149 | $end = array();  | 
            ||
| 150 | $fromLength = count($from);  | 
            ||
| 151 | $toLength = count($to);  | 
            ||
| 152 | $length = min($fromLength, $toLength);  | 
            ||
| 153 | |||
| 154 |         for ($i = 0; $i < $length; ++$i) { | 
            ||
| 155 |             if ($from[$i] === $to[$i]) { | 
            ||
| 156 | $start[] = $from[$i];  | 
            ||
| 157 | unset($from[$i], $to[$i]);  | 
            ||
| 158 |             } else { | 
            ||
| 159 | break;  | 
            ||
| 160 | }  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 | $length -= $i;  | 
            ||
| 164 | |||
| 165 |         for ($i = 1; $i < $length; ++$i) { | 
            ||
| 166 |             if ($from[$fromLength - $i] === $to[$toLength - $i]) { | 
            ||
| 167 | array_unshift($end, $from[$fromLength - $i]);  | 
            ||
| 168 | unset($from[$fromLength - $i], $to[$toLength - $i]);  | 
            ||
| 169 |             } else { | 
            ||
| 170 | break;  | 
            ||
| 171 | }  | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 |         if ($lcs === null) { | 
            ||
| 175 | $lcs = $this->selectLcsImplementation($from, $to);  | 
            ||
| 176 | }  | 
            ||
| 177 | |||
| 178 | $common = $lcs->calculate(array_values($from), array_values($to));  | 
            ||
| 179 | $diff = array();  | 
            ||
| 180 | |||
| 181 | if (isset($fromMatches[0]) && $toMatches[0] &&  | 
            ||
| 182 | count($fromMatches[0]) === count($toMatches[0]) &&  | 
            ||
| 183 |             $fromMatches[0] !== $toMatches[0]) { | 
            ||
| 184 | $diff[] = array(  | 
            ||
| 185 | '#Warning: Strings contain different line endings!', 0  | 
            ||
| 186 | );  | 
            ||
| 187 | }  | 
            ||
| 188 | |||
| 189 |         foreach ($start as $token) { | 
            ||
| 190 | $diff[] = array($token, 0 /* OLD */);  | 
            ||
| 191 | }  | 
            ||
| 192 | |||
| 193 | reset($from);  | 
            ||
| 194 | reset($to);  | 
            ||
| 195 | |||
| 196 |         foreach ($common as $token) { | 
            ||
| 197 |             while ((($fromToken = reset($from)) !== $token)) { | 
            ||
| 198 | $diff[] = array(array_shift($from), 2 /* REMOVED */);  | 
            ||
| 199 | }  | 
            ||
| 200 | |||
| 201 |             while ((($toToken = reset($to)) !== $token)) { | 
            ||
| 202 | $diff[] = array(array_shift($to), 1 /* ADDED */);  | 
            ||
| 203 | }  | 
            ||
| 204 | |||
| 205 | $diff[] = array($token, 0 /* OLD */);  | 
            ||
| 206 | |||
| 207 | array_shift($from);  | 
            ||
| 208 | array_shift($to);  | 
            ||
| 209 | }  | 
            ||
| 210 | |||
| 211 |         while (($token = array_shift($from)) !== null) { | 
            ||
| 212 | $diff[] = array($token, 2 /* REMOVED */);  | 
            ||
| 213 | }  | 
            ||
| 214 | |||
| 215 |         while (($token = array_shift($to)) !== null) { | 
            ||
| 216 | $diff[] = array($token, 1 /* ADDED */);  | 
            ||
| 217 | }  | 
            ||
| 218 | |||
| 219 |         foreach ($end as $token) { | 
            ||
| 220 | $diff[] = array($token, 0 /* OLD */);  | 
            ||
| 221 | }  | 
            ||
| 222 | |||
| 223 | return $diff;  | 
            ||
| 224 | }  | 
            ||
| 225 | |||
| 262 |