Completed
Push — master ( 0a1c77...2f1c32 )
by Vladimir
02:48
created

InArray::strict()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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