Passed
Branch 1.0 (f7255b)
by Vladimir
06:00
created

Contains   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

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\Helpers\Str;
8
use FondBot\Drivers\ReceivedMessage;
9
10
class Contains implements Activator
11
{
12
    private $needles;
13
14
    /**
15
     * @param array|string $needles
16
     */
17 4
    public function __construct($needles)
18
    {
19 4
        $this->needles = $needles;
20 4
    }
21
22
    /**
23
     * Result of matching activator.
24
     *
25
     * @param ReceivedMessage $message
26
     *
27
     * @return bool
28
     */
29 3
    public function matches(ReceivedMessage $message): bool
30
    {
31 3
        $text = $message->getText();
32 3
        if ($text === null) {
33 1
            return false;
34
        }
35
36 2
        return Str::contains($text, (array) $this->needles);
37
    }
38
}
39