| Conditions | 11 |
| Paths | 108 |
| Total Lines | 40 |
| 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 |
||
| 96 | public function getWords($text, $wc=false) |
||
| 97 | { |
||
| 98 | $wc = ($wc) ? '' : '\*'; |
||
| 99 | |||
| 100 | // prepare the text to be tokenized |
||
| 101 | $event = new Event('INDEXER_TEXT_PREPARE', $text); |
||
| 102 | if ($event->advise_before(true)) { |
||
| 103 | if (preg_match('/[^0-9A-Za-z ]/u', $text)) { |
||
| 104 | $text = Utf8\Asian::separateAsianWords($text); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $event->advise_after(); |
||
| 108 | unset($event); |
||
| 109 | |||
| 110 | $text = strtr($text, |
||
| 111 | array( |
||
| 112 | "\r" => ' ', |
||
| 113 | "\n" => ' ', |
||
| 114 | "\t" => ' ', |
||
| 115 | "\xC2\xAD" => '', //soft-hyphen |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | if (preg_match('/[^0-9A-Za-z ]/u', $text)) { |
||
| 119 | $text = Utf8\Clean::stripspecials($text, ' ', '\._\-:'.$wc); |
||
| 120 | } |
||
| 121 | |||
| 122 | $wordlist = explode(' ', $text); |
||
| 123 | foreach ($wordlist as $i => $word) { |
||
| 124 | $wordlist[$i] = (preg_match('/[^0-9A-Za-z]/u', $word)) ? |
||
| 125 | Utf8\PhpString::strtolower($word) : strtolower($word); |
||
| 126 | } |
||
| 127 | |||
| 128 | foreach ($wordlist as $i => $word) { |
||
| 129 | if ((!is_numeric($word) && strlen($word) < $this->MinWordLength) |
||
| 130 | || array_search($word, $this->getStopwords(), true) !== false) { |
||
| 131 | unset($wordlist[$i]); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | return array_values($wordlist); |
||
| 135 | } |
||
| 136 | } |
||
| 137 |