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

Contains::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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