In::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
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 In implements Activator
12
{
13
    protected $values;
14
15
    /**
16
     * InArray constructor.
17
     *
18
     * @param array|Collection $values
19
     */
20 5
    protected function __construct($values)
21
    {
22 5
        if ($values instanceof Collection) {
23 2
            $values = $values->toArray();
24
        }
25
26 5
        $this->values = $values;
27 5
    }
28
29
    /**
30
     * @param array|Collection $values
31
     *
32
     * @return static
33
     */
34 5
    public static function make($values)
35
    {
36 5
        return new static($values);
37
    }
38
39
    /**
40
     * Result of matching activator.
41
     *
42
     * @param MessageReceived $message
43
     *
44
     * @return bool
45
     */
46 4
    public function matches(MessageReceived $message): bool
47
    {
48 4
        $haystack = $this->values;
49
50 4
        if ($haystack instanceof Collection) {
51
            $haystack = $haystack->toArray();
52
        }
53
54 4
        return in_array($message->getText(), $haystack, false);
55
    }
56
}
57