Completed
Push — master ( de59c0...367b4e )
by Vladimir
03:16
created

Attachment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 11
    public function __construct(string $type = null)
16
    {
17 11
        $this->type = $type;
18 11
    }
19
20
    public function file(): self
21
    {
22
        $this->type = Template::TYPE_FILE;
23
24
        return $this;
25
    }
26
27
    public function image(): self
28
    {
29
        $this->type = Template::TYPE_IMAGE;
30
31
        return $this;
32
    }
33
34
    public function audio(): self
35
    {
36
        $this->type = Template::TYPE_AUDIO;
37
38
        return $this;
39
    }
40
41
    public function video(): self
42
    {
43
        $this->type = Template::TYPE_VIDEO;
44
45
        return $this;
46
    }
47
48
    /**
49
     * Result of matching activator.
50
     *
51
     * @param MessageReceived $message
52
     *
53
     * @return bool
54
     */
55 10
    public function matches(MessageReceived $message): bool
56
    {
57 10
        if ($this->type === null) {
58 2
            return $message->getAttachment() !== null;
59
        }
60
61 8
        return hash_equals($message->getAttachment()->getType(), $this->type);
62
    }
63
}
64