Passed
Push — hotfix/fix-counts ( 4b43d1...cc9e05 )
by Paul
03:52
created

Blacklist::isBlacklisted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Database\OptionManager;
6
7
class Blacklist
8
{
9
    /**
10
     * @return bool
11
     */
12 1
    public function isBlacklisted(array $review)
13
    {
14 1
        $target = implode("\n", array_filter([
15 1
            $review['name'],
16 1
            $review['content'],
17 1
            $review['email'],
18 1
            $review['ip_address'],
19 1
            $review['title'],
20
        ]));
21 1
        return (bool) apply_filters('site-reviews/blacklist/is-blacklisted',
22 1
            $this->check($target),
23 1
            $review
24
        );
25
    }
26
27
    /**
28
     * @param string $target
29
     * @return bool
30
     */
31 1
    protected function check($target)
32
    {
33 1
        $blacklist = trim(glsr(OptionManager::class)->get('settings.submissions.blacklist.entries'));
34 1
        if (empty($blacklist)) {
35 1
            return false;
36
        }
37
        $lines = explode("\n", $blacklist);
38
        foreach ((array) $lines as $line) {
39
            $line = trim($line);
40
            if (empty($line) || 256 < strlen($line)) {
41
                continue;
42
            }
43
            $pattern = sprintf('#%s#i', preg_quote($line, '#'));
44
            if (preg_match($pattern, $target)) {
45
                return true;
46
            }
47
        }
48
        return false;
49
    }
50
}
51