| Conditions | 16 |
| Paths | 54 |
| Total Lines | 50 |
| Code Lines | 30 |
| 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 |
||
| 64 | public function extract() |
||
| 65 | { |
||
| 66 | if ($this->onlyInSentence) { |
||
| 67 | $sentences = []; |
||
| 68 | foreach (explode(chr(10), $this->text) as $paragraph) { |
||
| 69 | $sentences = array_merge($sentences, CleanText::getSentences($paragraph)); |
||
| 70 | } |
||
| 71 | } else { |
||
| 72 | $sentences = explode(chr(10), trim($this->text)); |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($sentences as $sentence) { |
||
| 76 | $sentence = CleanText::removePunctuation($sentence); |
||
| 77 | |||
| 78 | $words = explode(' ', trim(strtolower($sentence))); |
||
| 79 | |||
| 80 | foreach ($words as $key => $word) { |
||
| 81 | for ($wordNumber = 1; $wordNumber < $this->expressionMaxWords; ++$wordNumber) { |
||
| 82 | $expression = ''; |
||
| 83 | for ($i = 0; $i < $wordNumber; ++$i) { |
||
| 84 | if (isset($words[$key + $i])) { |
||
| 85 | $expression .= ($i > 0 ? ' ' : '').$words[$key + $i]; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | $expression = $this->cleanExpr($expression, $wordNumber); |
||
| 90 | |||
| 91 | if ( |
||
| 92 | empty($expression) |
||
| 93 | || ((substr_count($expression, ' ') + 1) != $wordNumber) // We avoid sur-pondération |
||
| 94 | || !preg_match('/[a-z]/', $expression) // We avoid number or symbol only result |
||
| 95 | ) { |
||
| 96 | if (1 === $wordNumber) { |
||
| 97 | $this->incrementWordNumber(-1); |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | $plus = 1 + substr_count(CleanText::removeStopWords($expression), ' '); |
||
| 101 | $this->expressions[$expression] = isset($this->expressions[$expression]) ? $this->expressions[$expression] + $plus : $plus; |
||
| 102 | if ($this->keepTrail > 0 && $this->expressions[$expression] > $this->keepTrail) { |
||
| 103 | $this->trail[$expression][] = $sentence; |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $this->incrementWordNumber(1); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | arsort($this->expressions); |
||
| 112 | |||
| 113 | return $this->expressions; |
||
| 114 | } |
||
| 167 |