Passed
Push — master ( d9b23e...c2fe70 )
by Arthur
01:41
created

Phrases::processPhrases()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.9777
c 0
b 0
f 0
cc 6
nc 10
nop 0
1
<?php
2
3
namespace detox\core;
4
5
class Phrases extends Words
6
{
7
    /**
8
     * Finds phrases from *Set and sets score/replacements
9
     */
10
    public function processPhrases()
11
    {
12
        // to match lower case letters in words set array
13
        $lowerSource = $this->addLowSpaces($this->text->getString());
14
        /**
15
         * @var string $points
16
         * @var array $phrases
17
         */
18
        foreach ($this->dataSet->getPhrases() as $points => $phrases) {
19
            foreach ($phrases as $phrase) {
20
                if (mb_strpos($lowerSource, ' ' . $phrase . ' ') !== false) {
21
                    $this->score += (float)$points;
22
                    if ($this->text->isReplaceable()) {
23
                        $this->replace($phrase);
24
                    }
25
                }
26
            }
27
        }
28
        if ($this->score >= self::MAX_SCORE) {
29
            $this->score = self::MAX_SCORE;
30
        }
31
    }
32
}