Basic::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
    protected ASources $source;
13
    protected string $searchKey = '';
14
15 22
    public function __construct(ASources $source, ?IKBTranslations $lang = null)
16
    {
17 22
        $this->source = $source;
18 22
    }
19
20 17
    public function setLookedFor(string $lookedFor): void
21
    {
22 17
        $this->searchKey = $lookedFor;
23 17
    }
24
25 17
    protected function matched(): array
26
    {
27
        // compare string with array of all banned strings
28 17
        $s = mb_strtolower($this->searchKey);
29 17
        $foundRecords = [];
30 17
        foreach ($this->source->getRecords() as $index => $word) {
31 17
            $found = mb_strpos($s, mb_strtolower($word));
32 17
            if (false !== $found) {
33 6
                $foundRecords[$index] = intval($found);
34
            }
35
        }
36 17
        return $foundRecords;
37
    }
38
}
39