Completed
Push — master ( d5e8bc...fafbf7 )
by Vladimir
02:59
created

Regex   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A make() 0 4 1
A matches() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use Illuminate\Support\Collection;
8
use FondBot\Events\MessageReceived;
9
use FondBot\Contracts\Conversation\Activator;
10
11
class Regex implements Activator
12
{
13
    /** @var array|string */
14
    protected $patterns;
15
16 2
    protected function __construct($patterns)
17
    {
18 2
        if ($patterns instanceof Collection) {
19
            $patterns = $patterns->toArray();
20
        }
21
22 2
        $this->patterns = $patterns;
23 2
    }
24
25 2
    public static function make($patterns)
26
    {
27 2
        return new static($patterns);
28
    }
29
30
    /**
31
     * Result of matching activator.
32
     *
33
     * @param MessageReceived $message
34
     *
35
     * @return bool
36
     */
37 2
    public function matches(MessageReceived $message): bool
38
    {
39 2
        return str_is($this->patterns, $message->getText());
40
    }
41
}
42