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

In   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
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 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