Passed
Push — 1.0 ( 12d132...dd1957 )
by Vladimir
06:10
created

Attachment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 76
ccs 19
cts 19
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getType() 0 4 1
A getPath() 0 4 1
A getMetadata() 0 4 1
A possibleTypes() 0 9 1
A toArray() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Templates;
6
7
use FondBot\Contracts\Arrayable;
8
9
class Attachment implements Arrayable
10
{
11
    public const TYPE_FILE = 'file';
12
    public const TYPE_IMAGE = 'image';
13
    public const TYPE_AUDIO = 'audio';
14
    public const TYPE_VIDEO = 'video';
15
16
    protected $type;
17
    protected $path;
18
    protected $metadata;
19
20 12
    public function __construct(string $type, string $path, array $metadata = [])
21
    {
22 12
        $this->type = $type;
23 12
        $this->path = $path;
24 12
        $this->metadata = $metadata;
25 12
    }
26
27
    /**
28
     * Get attachment type.
29
     *
30
     * @return string
31
     */
32 12
    public function getType(): string
33
    {
34 12
        return $this->type;
35
    }
36
37
    /**
38
     * Get path to the attachment.
39
     *
40
     * @return string
41
     */
42 4
    public function getPath(): string
43
    {
44 4
        return $this->path;
45
    }
46
47
    /**
48
     * Get attachment metadata.
49
     *
50
     * @return array
51
     */
52 4
    public function getMetadata(): array
53
    {
54 4
        return $this->metadata;
55
    }
56
57
    /**
58
     * Get all types.
59
     *
60
     * @return array
61
     */
62 5
    public static function possibleTypes(): array
63
    {
64
        return [
65 5
            static::TYPE_FILE,
66 5
            static::TYPE_IMAGE,
67 5
            static::TYPE_AUDIO,
68 5
            static::TYPE_VIDEO,
69
        ];
70
    }
71
72
    /**
73
     * Get the instance as an array.
74
     *
75
     * @return array
76
     */
77 4
    public function toArray(): array
78
    {
79
        return [
80 4
            'type' => $this->type,
81 4
            'path' => $this->path,
82
        ];
83
    }
84
}
85