| Conditions | 22 |
| Paths | 32 |
| Total Lines | 74 |
| Code Lines | 57 |
| 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 |
||
| 213 | protected function convertHtmlToListOfWords($characterString) |
||
| 214 | { |
||
| 215 | $mode = 'character'; |
||
| 216 | $current_word = ''; |
||
| 217 | $words = array(); |
||
| 218 | foreach ($characterString as $i => $character) { |
||
| 219 | switch ($mode) { |
||
| 220 | case 'character': |
||
| 221 | if ( $this->isStartOfTag( $character ) ) { |
||
| 222 | if ($current_word != '') { |
||
| 223 | $words[] = $current_word; |
||
| 224 | } |
||
| 225 | $current_word = "<"; |
||
| 226 | $mode = 'tag'; |
||
| 227 | } elseif ( preg_match( "[^\s]", $character ) > 0 ) { |
||
| 228 | if ($current_word != '') { |
||
| 229 | $words[] = $current_word; |
||
| 230 | } |
||
| 231 | $current_word = $character; |
||
| 232 | $mode = 'whitespace'; |
||
| 233 | } else { |
||
| 234 | if ( |
||
| 235 | (ctype_alnum($character) && (strlen($current_word) == 0 || $this->isPartOfWord($current_word))) || |
||
| 236 | (in_array($character, $this->specialCaseChars) && isset($characterString[$i+1]) && $this->isPartOfWord($characterString[$i+1])) |
||
| 237 | ) { |
||
| 238 | $current_word .= $character; |
||
| 239 | } else { |
||
| 240 | $words[] = $current_word; |
||
| 241 | $current_word = $character; |
||
| 242 | } |
||
| 243 | } |
||
| 244 | break; |
||
| 245 | case 'tag' : |
||
| 246 | if ( $this->isEndOfTag( $character ) ) { |
||
| 247 | $current_word .= ">"; |
||
| 248 | $words[] = $current_word; |
||
| 249 | $current_word = ""; |
||
| 250 | |||
| 251 | if ( !preg_match('[^\s]', $character ) ) { |
||
| 252 | $mode = 'whitespace'; |
||
| 253 | } else { |
||
| 254 | $mode = 'character'; |
||
| 255 | } |
||
| 256 | } else { |
||
| 257 | $current_word .= $character; |
||
| 258 | } |
||
| 259 | break; |
||
| 260 | case 'whitespace': |
||
| 261 | if ( $this->isStartOfTag( $character ) ) { |
||
| 262 | if ($current_word != '') { |
||
| 263 | $words[] = $current_word; |
||
| 264 | } |
||
| 265 | $current_word = "<"; |
||
| 266 | $mode = 'tag'; |
||
| 267 | } elseif ( preg_match( "[^\s]", $character ) ) { |
||
| 268 | $current_word .= $character; |
||
| 269 | } else { |
||
| 270 | if ($current_word != '') { |
||
| 271 | $words[] = $current_word; |
||
| 272 | } |
||
| 273 | $current_word = $character; |
||
| 274 | $mode = 'character'; |
||
| 275 | } |
||
| 276 | break; |
||
| 277 | default: |
||
| 278 | break; |
||
| 279 | } |
||
| 280 | } |
||
| 281 | if ($current_word != '') { |
||
| 282 | $words[] = $current_word; |
||
| 283 | } |
||
| 284 | |||
| 285 | return $words; |
||
| 286 | } |
||
| 287 | |||
| 309 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.