Regex::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

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