Attachment   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 8
eloc 15
dl 0
loc 56
c 0
b 0
f 0
ccs 9
cts 21
cp 0.4286
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A make() 0 3 1
A matches() 0 7 2
A video() 0 5 1
A file() 0 5 1
A audio() 0 5 1
A image() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Conversation\Activators;
6
7
use FondBot\Contracts\Activator;
8
use FondBot\Events\MessageReceived;
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