Passed
Push — master ( 2e2f76...4a0b2a )
by Arthur
01:32
created

Phrases   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A processPhrases() 0 18 5
1
<?php
2
3
namespace detox\core;
4
5
class Phrases extends Words
6
{
7
    /**
8
     * @param string $source
9
     */
10
    public function processPhrases(string $source)
11
    {
12
        // to match lower case letters in words set array
13
        $lowerSource = $this->addLowSpaces($source);
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
                }
23
                if ($this->score >= self::MAX_SCORE) {
24
                    $this->score = self::MAX_SCORE;
25
26
                    // we don't need to iterate more with max score
27
                    return;
28
                }
29
            }
30
        }
31
    }
32
}