Completed
Push — master ( 0a1c77...2f1c32 )
by Vladimir
02:48
created

Exact   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A caseSensitive() 0 6 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
use FondBot\Contracts\Conversation\Activator;
10
11
class Exact implements Activator
12
{
13
    protected $value;
14
    protected $caseSensitive;
15
16 6
    public function __construct(string $value, bool $caseSensitive = false)
17
    {
18 6
        $this->value = $value;
19 6
        $this->caseSensitive = $caseSensitive;
20 6
    }
21
22
    public function caseSensitive(bool $caseSensitive): self
23
    {
24
        $this->caseSensitive = $caseSensitive;
25
26
        return $this;
27
    }
28
29
    /**
30
     * Result of matching activator.
31
     *
32
     * @param MessageReceived $message
33
     *
34
     * @return bool
35
     */
36 5
    public function matches(MessageReceived $message): bool
37
    {
38 5
        $text = $message->getText();
39 5
        if ($text === null) {
40
            return false;
41
        }
42
43 5
        if (!$this->caseSensitive) {
44 3
            $text = Str::lower($text);
45 3
            $this->value = Str::lower($this->value);
46
        }
47
48 5
        return hash_equals($this->value, $text);
49
    }
50
}
51