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

Attachment   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 36.84%

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 7
cts 19
cp 0.3684
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

6 Methods

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