Passed
Push — master ( de3770...e18c28 )
by Petr
07:43
created

Basic::matched()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 12
ccs 8
cts 8
cp 1
crap 3
rs 10
1
<?php
2
3
namespace kalanis\kw_bans\Bans;
4
5
6
use kalanis\kw_bans\Interfaces\IKBTranslations;
7
use kalanis\kw_bans\Sources\ASources;
8
9
10
class Basic extends ABan
11
{
12
    /** @var ASources */
13
    protected $source = null;
14
    /** @var string */
15
    protected $searchKey = '';
16
17 22
    public function __construct(ASources $source, ?IKBTranslations $lang = null)
18
    {
19 22
        $this->source = $source;
20 22
    }
21
22 17
    public function setLookedFor(string $lookedFor): void
23
    {
24 17
        $this->searchKey = $lookedFor;
25 17
    }
26
27 17
    protected function matched(): array
28
    {
29
        // compare string with array of all banned strings
30 17
        $s = mb_strtolower($this->searchKey);
31 17
        $foundRecords = [];
32 17
        foreach ($this->source->getRecords() as $index => $word) {
33 17
            $found = mb_strpos($s, mb_strtolower($word));
34 17
            if (false !== $found) {
35 6
                $foundRecords[$index] = intval($found);
36
            }
37
        }
38 17
        return $foundRecords;
39
    }
40
}
41