Completed
Push — 2.0 ( add69f...60b181 )
by Nicolas
02:30
created

FileHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 0
cbo 1
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeByMimetype() 0 4 1
A getFaIcon() 0 11 3
A slug() 0 9 1
A getExtension() 0 4 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