Passed
Push — master ( 98541d...d359a0 )
by
unknown
08:18
created

Exact::matches()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 0
Metric Value
dl 0
loc 14
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.4285
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use Illuminate\Support\Str;
8
use FondBot\Events\MessageReceived;
9
10
class Exact implements Activator
11
{
12
    private $value;
13
    private $caseSensitive;
14
15 6
    public function __construct(string $value, bool $caseSensitive = false)
16
    {
17 6
        $this->value = $value;
18 6
        $this->caseSensitive = $caseSensitive;
19 6
    }
20
21
    /**
22
     * Result of matching activator.
23
     *
24
     * @param MessageReceived $message
25
     *
26
     * @return bool
27
     */
28 5
    public function matches(MessageReceived $message): bool
29
    {
30 5
        $text = $message->getText();
31 5
        if ($text === null) {
32
            return false;
33
        }
34
35 5
        if (!$this->caseSensitive) {
36 3
            $text = Str::lower($text);
37 3
            $this->value = Str::lower($this->value);
38
        }
39
40 5
        return hash_equals($this->value, $text);
41
    }
42
}
43