Completed
Push — master ( a22976...bdfc9e )
by Vladimir
03:53
created

In   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 11
cts 12
cp 0.9167
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

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