SilentSpam::isSpam()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Breadthe\SilentSpam;
4
5
class SilentSpam
6
{
7
    protected $blacklist = [];
8
9
    /**
10
     * Amend the silentspam config blacklist at runtime with additional criteria.
11
     *
12
     * @param array $keywords
13
     */
14
    public function blacklist(array $keywords = [])
15
    {
16
        $this->blacklist = $keywords;
17
    }
18
19
    public function isSpam($message)
20
    {
21
        foreach (array_merge(config('silentspam.blacklist') ?? [], $this->blacklist) as $keyword) {
22
            if (preg_match("/{$keyword}/i", $message)) {
23
                return true;
24
            }
25
        }
26
27
        return false;
28
    }
29
30
    public function notSpam($message)
31
    {
32
        return ! $this->isSpam($message);
33
    }
34
}
35