Completed
Push — master ( 70a760...de59c0 )
by Vladimir
04:07 queued 01:42
created

Regex::matches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use FondBot\Events\MessageReceived;
8
use Spatie\Regex\Regex as SpatieRegex;
9
use FondBot\Contracts\Conversation\Activator;
10
11
class Regex implements Activator
12
{
13
    protected $pattern;
14
15 3
    public function __construct(string $pattern)
16
    {
17 3
        $this->pattern = $pattern;
18 3
    }
19
20
    /**
21
     * Result of matching activator.
22
     *
23
     * @param MessageReceived $message
24
     *
25
     * @return bool
26
     */
27 2
    public function matches(MessageReceived $message): bool
28
    {
29 2
        $text = $message->getText();
30
31 2
        return SpatieRegex::match($this->pattern, $text)->hasMatch();
32
    }
33
}
34