Completed
Push — master ( a600c8...2307b6 )
by Vladimir
03:01
created

In::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
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 Illuminate\Support\Collection;
8
use FondBot\Events\MessageReceived;
9
use FondBot\Contracts\Conversation\Activator;
10
11
class In implements Activator
12
{
13
    protected $values;
14
15
    /**
16
     * InArray constructor.
17
     *
18
     * @param array|Collection $values
19
     */
20 7
    public function __construct($values)
21
    {
22 7
        if ($values instanceof Collection) {
23 3
            $values = $values->toArray();
24
        }
25
26 7
        $this->values = $values;
27 7
    }
28
29
    /**
30
     * Result of matching activator.
31
     *
32
     * @param MessageReceived $message
33
     *
34
     * @return bool
35
     */
36 4
    public function matches(MessageReceived $message): bool
37
    {
38 4
        $haystack = $this->values;
39
40 4
        if ($haystack instanceof Collection) {
41
            $haystack = $haystack->toArray();
42
        }
43
44 4
        return in_array($message->getText(), $haystack, false);
45
    }
46
}
47