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

Attachment   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 9
cts 21
cp 0.4286
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 4 1
A file() 0 6 1
A image() 0 6 1
A audio() 0 6 1
A video() 0 6 1
A matches() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use FondBot\Events\MessageReceived;
8
use FondBot\Contracts\Conversation\Activator;
9
use FondBot\Templates\Attachment as Template;
10
11
class Attachment implements Activator
12
{
13
    protected $type;
14
15 10
    protected function __construct(string $type = null)
16
    {
17 10
        $this->type = $type;
18 10
    }
19
20 10
    public static function make(string $type = null)
21
    {
22 10
        return new static($type);
23
    }
24
25
    public function file(): self
26
    {
27
        $this->type = Template::TYPE_FILE;
28
29
        return $this;
30
    }
31
32
    public function image(): self
33
    {
34
        $this->type = Template::TYPE_IMAGE;
35
36
        return $this;
37
    }
38
39
    public function audio(): self
40
    {
41
        $this->type = Template::TYPE_AUDIO;
42
43
        return $this;
44
    }
45
46
    public function video(): self
47
    {
48
        $this->type = Template::TYPE_VIDEO;
49
50
        return $this;
51
    }
52
53
    /**
54
     * Result of matching activator.
55
     *
56
     * @param MessageReceived $message
57
     *
58
     * @return bool
59
     */
60 10
    public function matches(MessageReceived $message): bool
61
    {
62 10
        if ($this->type === null) {
63 2
            return $message->getAttachment() !== null;
64
        }
65
66 8
        return hash_equals($message->getAttachment()->getType(), $this->type);
67
    }
68
}
69