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

Regex::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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