Type   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 58
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
A all() 0 9 1
A getByMimeType() 0 11 4
1
<?php
2
declare(strict_types=1);
3
4
namespace tkanstantsin\fileupload\model;
5
6
/**
7
 * Class FileType
8
 */
9
class Type
10
{
11
    public const FILE = 1;
12
    public const IMAGE = 2;
13
    public const DOC = 3;
14
    public const VIDEO = 4;
15
    public const AUDIO = 5;
16
    public const ARCHIVE = 5;
17
18
    public static $folderPrefix = [
19
        self::FILE => 'file',
20
        self::IMAGE => 'image',
21
        self::DOC => 'doc',
22
        self::VIDEO => 'video',
23
        self::AUDIO => 'audio',
24
        self::ARCHIVE => 'archive',
25
    ];
26
27
    /**
28
     * @return array
29
     */
30
    public static function all(): array
31
    {
32
        return [
33
            self::FILE => 'File',
34
            self::IMAGE => 'Image',
35
            self::DOC => 'Document',
36
            self::VIDEO => 'Video',
37
            self::AUDIO => 'Audio',
38
            self::ARCHIVE => 'Archive',
39
        ];
40
    }
41
42
    /**
43
     * @param int $id
44
     * @return string
45
     */
46
    public static function get(int $id): ?string
47
    {
48
        return static::all()[$id] ?? null;
49
    }
50
51
    /**
52
     * Returns file type by its mime type.
53
     * @param string|null $mimeType
54
     * @return int
55
     */
56
    public static function getByMimeType(?string $mimeType): int
57
    {
58
        switch (explode('/', (string) $mimeType)[0] ?? null) {
59
            case 'image':
60
                return static::IMAGE;
61
            case 'audio':
62
                return static::AUDIO;
63
            case 'video':
64
                return static::VIDEO;
65
            default:
66
                return static::FILE;
67
        }
68
    }
69
}