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

Exact   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 33
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
rs 10
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 14 3
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