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

InArray   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
dl 0
loc 42
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A strict() 0 6 1
A matches() 0 10 2
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