Passed
Push — master ( 98541d...d359a0 )
by
unknown
08:18
created

Contains   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
dl 0
loc 29
c 0
b 0
f 0
ccs 7
cts 8
cp 0.875
rs 10
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A matches() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use FondBot\Events\MessageReceived;
8
9
class Contains implements Activator
10
{
11
    private $needles;
12
13
    /**
14
     * @param array|string $needles
15
     */
16 4
    public function __construct($needles)
17
    {
18 4
        $this->needles = $needles;
19 4
    }
20
21
    /**
22
     * Result of matching activator.
23
     *
24
     * @param MessageReceived $message
25
     *
26
     * @return bool
27
     */
28 3
    public function matches(MessageReceived $message): bool
29
    {
30 3
        $text = $message->getText();
31 3
        if ($text === null) {
32
            return false;
33
        }
34
35 3
        return str_contains($text, (array) $this->needles);
36
    }
37
}
38