Issues (16)

src/Conversation/Activators/Contains.php (2 issues)

Severity
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 Contains implements Activator
12
{
13
    protected $needles;
14
15
    /**
16
     * @param array|string $needles
17
     */
18 4
    protected function __construct($needles)
19
    {
20 4
        if ($needles instanceof Collection) {
0 ignored issues
show
$needles is never a sub-type of Illuminate\Support\Collection.
Loading history...
21
            $needles = $needles->toArray();
22
        }
23
24 4
        $this->needles = $needles;
25 4
    }
26
27
    /**
28
     * @param array|string $needles
29
     *
30
     * @return static
31
     */
32 4
    public static function make($needles)
33
    {
34 4
        return new static($needles);
35
    }
36
37
    /**
38
     * Result of matching activator.
39
     *
40
     * @param MessageReceived $message
41
     *
42
     * @return bool
43
     */
44 3
    public function matches(MessageReceived $message): bool
45
    {
46 3
        $text = $message->getText();
47 3
        if ($text === null) {
0 ignored issues
show
The condition $text === null is always false.
Loading history...
48
            return false;
49
        }
50
51 3
        return str_contains($text, (array) $this->needles);
52
    }
53
}
54