Completed
Pull Request — 2.0 (#49)
by
unknown
03:04
created

FileHelper::getTypeByMimetype()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Modules\Media\Helpers;
4
5
use Illuminate\Support\Str;
6
7
class FileHelper
8
{
9
    /**
10
     * Get first token of string before delimiter
11
     * @param $mimetype
12
     * @return string
13
     */
14
    public static function getTypeByMimetype($mimetype)
15
    {
16
        return strtok($mimetype, '/');
17
    }
18
19
    /**
20
     * Get Font Awesome icon for various files
21
     * @param string $mediaType
22
     * @return string
23
     */
24
    public static function getFaIcon($mediaType)
25
    {
26
        switch ($mediaType) {
27
            case 'video':
28
                return 'fa-file-video-o';
29
            case 'audio':
30
                return 'fa-file-audio-o';
31
            default:
32
                return 'fa-file';
33
        }
34
    }
35
36
    public static function slug($name)
37
    {
38
        $extension = self::getExtension($name);
39
        $name = str_replace($extension, '', $name);
40
41
        $name = Str::slug($name);
42
43
        return $name . strtolower($extension);
44
    }
45
46
    /**
47
     * Get the extension from the given name
48
     * @param $name
49
     * @return string
50
     */
51
    private static function getExtension($name)
52
    {
53
        return substr($name, strrpos($name, '.'));
54
    }
55
}
56