Exact::caseSensitive()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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