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
Pull Request — main (#4988)
by Cristian
29:54 queued 14:57
created

FileNameGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 19
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 getName() 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
    public function getName(string|UploadedFile $file): string
12
    {
13
        return $this->getFileName($file).'.'.$this->getExtensionFromFile($file);
14
    }
15
16
    private function getExtensionFromFile(string|UploadedFile $file): string
17
    {
18
        return is_a($file, UploadedFile::class, true) ? $file->extension() : Str::after(mime_content_type($file), '/');
19
    }
20
21
    private function getFileName(string|UploadedFile $file): string
22
    {
23
        if (is_file($file)) {
24
            return Str::of($file->getClientOriginalName())->beforeLast('.')->slug()->append('-'.Str::random(4));
25
        }
26
27
        return Str::random(40);
28
    }
29
}
30