| Conditions | 11 |
| Paths | 20 |
| Total Lines | 35 |
| Code Lines | 17 |
| 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 |
||
| 42 | public function processWords() : void |
||
| 43 | { |
||
| 44 | // to match lower case letters in words set array |
||
| 45 | $lowerSource = $this->addLowSpaces($this->text->getString()); |
||
| 46 | /** |
||
| 47 | * 1st level checking discrete words with spaces |
||
| 48 | * @var string $points |
||
| 49 | * @var array $words |
||
| 50 | */ |
||
| 51 | foreach ($this->dataSet->getWords() as $points => $words) { |
||
| 52 | foreach ($words as $word) { |
||
| 53 | if (mb_strpos($lowerSource, ' ' . $word . ' ') !== false) { |
||
| 54 | $this->score += (float)$points; |
||
| 55 | if ($this->text->isReplaceable()) { |
||
| 56 | $this->replace($word); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | if ($this->score < self::ASTERISKS_MIDDLE) { |
||
| 62 | // 2nd level checking the worst (3 highest levels) words with probability to be mutated ex.: shittyass, crappish, unfuckkish etc |
||
| 63 | $slice = array_slice($this->dataSet->getWords(), 0, 3); |
||
| 64 | foreach ($slice as $points => $words) { |
||
| 65 | foreach ($words as $word) { |
||
| 66 | if (mb_strpos($lowerSource, $word) !== false) { |
||
| 67 | $this->score += (float)$points; |
||
| 68 | if ($this->text->isReplaceable()) { |
||
| 69 | $this->replace($word); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | if ($this->score >= self::MAX_SCORE) { |
||
| 76 | $this->score = self::MAX_SCORE; |
||
| 77 | } |
||
| 191 | } |