Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — crud-uploads ( f5e93a...469ece )
by Pedro
11:36
created

FileNameGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getExtensionFromFile() 0 3 2
A getFileName() 0 7 2
A generate() 0 3 1
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Uploaders\Support;
4
5
use Backpack\CRUD\app\Library\Uploaders\Support\Interfaces\FileNameGeneratorInterface;
6
use Illuminate\Http\UploadedFile;
7
use Illuminate\Support\Str;
8
9
class FileNameGenerator implements FileNameGeneratorInterface
10
{
11
    /**
12
     * Generate a unique file name.
13
     *
14
     * @param  string|UploadedFile  $file
15
     * @return string
16
     */
17
    public function generate($file)
18
    {
19
        return $this->getFileName($file).'.'.$this->getExtensionFromFile($file);
20
    }
21
22
    /**
23
     * Return the file extension.
24
     *
25
     * @param  mixed  $file
26
     * @return string
27
     */
28
    private function getExtensionFromFile($file)
29
    {
30
        return is_a($file, UploadedFile::class, true) ? $file->extension() : Str::after(mime_content_type($file), '/');
31
    }
32
33
    /**
34
     * Return the file name.
35
     *
36
     * @param  mixed  $file
37
     * @return string
38
     */
39
    private function getFileName($file)
40
    {
41
        if (is_file($file)) {
42
            return Str::of($file->getClientOriginalName())->beforeLast('.')->slug()->append('-'.Str::random(4));
43
        }
44
45
        return Str::random(40);
46
    }
47
}
48