SilentSpam   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A blacklist() 0 4 1
A isSpam() 0 10 3
A notSpam() 0 4 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