Exact   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 43
c 0
b 0
f 0
ccs 15
cts 16
cp 0.9375
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A caseSensitive() 0 5 1
A matches() 0 14 3
A __construct() 0 3 1
A make() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use Illuminate\Support\Str;
8
use FondBot\Contracts\Activator;
9
use FondBot\Events\MessageReceived;
10
11
class Exact implements Activator
12
{
13
    protected $value;
14
    protected $caseSensitive;
15
16 6
    protected function __construct(string $value)
17
    {
18 6
        $this->value = $value;
19 6
    }
20
21 6
    public static function make(string $value)
22
    {
23 6
        return new static($value);
24
    }
25
26 1
    public function caseSensitive(): self
27
    {
28 1
        $this->caseSensitive = true;
29
30 1
        return $this;
31
    }
32
33
    /**
34
     * Result of matching activator.
35
     *
36
     * @param MessageReceived $message
37
     *
38
     * @return bool
39
     */
40 6
    public function matches(MessageReceived $message): bool
41
    {
42 6
        $text = $message->getText();
43
44 6
        if ($text === null) {
0 ignored issues
show
introduced by
The condition $text === null is always false.
Loading history...
45
            return false;
46
        }
47
48 6
        if (!$this->caseSensitive) {
49 5
            $text = Str::lower($text);
50 5
            $this->value = Str::lower($this->value);
51
        }
52
53 6
        return hash_equals($this->value, $text);
54
    }
55
}
56