Regex   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 29
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A __construct() 0 7 2
A matches() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use FondBot\Contracts\Activator;
8
use Illuminate\Support\Collection;
9
use FondBot\Events\MessageReceived;
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