| Conditions | 11 |
| Paths | 108 |
| Total Lines | 38 |
| 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 |
||
| 75 | public static function getWords($text, $wc = false) |
||
| 76 | { |
||
| 77 | $wc = ($wc) ? '' : '\*'; |
||
| 78 | |||
| 79 | // prepare the text to be tokenized |
||
| 80 | $event = new Event('INDEXER_TEXT_PREPARE', $text); |
||
| 81 | if ($event->advise_before(true)) { |
||
| 82 | if (preg_match('/[^0-9A-Za-z ]/u', $text)) { |
||
| 83 | $text = Utf8\Asian::separateAsianWords($text); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | $event->advise_after(); |
||
| 87 | unset($event); |
||
| 88 | |||
| 89 | $text = strtr($text, array( |
||
| 90 | "\r" => ' ', |
||
| 91 | "\n" => ' ', |
||
| 92 | "\t" => ' ', |
||
| 93 | "\xC2\xAD" => '', //soft-hyphen |
||
| 94 | )); |
||
| 95 | if (preg_match('/[^0-9A-Za-z ]/u', $text)) { |
||
| 96 | $text = Utf8\Clean::stripspecials($text, ' ', '\._\-:'.$wc); |
||
| 97 | } |
||
| 98 | |||
| 99 | $wordlist = explode(' ', $text); |
||
| 100 | foreach ($wordlist as $i => $word) { |
||
| 101 | $wordlist[$i] = (preg_match('/[^0-9A-Za-z]/u', $word)) ? |
||
| 102 | Utf8\PhpString::strtolower($word) : strtolower($word); |
||
| 103 | } |
||
| 104 | |||
| 105 | foreach ($wordlist as $i => $word) { |
||
| 106 | if ((!is_numeric($word) && strlen($word) < static::getMinWordLength()) |
||
| 107 | || array_search($word, static::getStopwords(), true) !== false) { |
||
| 108 | unset($wordlist[$i]); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | return array_values($wordlist); |
||
| 112 | } |
||
| 113 | } |
||
| 114 |