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 Pedro
43:09 queued 28:06
created

FileNameGenerator::getFileName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
use Symfony\Component\HttpFoundation\File\File;
9
10
class FileNameGenerator implements FileNameGeneratorInterface
11
{
12
    public function getName(string|UploadedFile|File $file): string
13
    {
14
        if (is_object($file) && get_class($file) === File::class) {
15
            return $file->getFileName();
16
        }
17
18
        return $this->getFileName($file).'.'.$this->getExtensionFromFile($file);
19
    }
20
21
    private function getExtensionFromFile(string|UploadedFile $file): string
22
    {
23
        return is_a($file, UploadedFile::class, true) ? $file->extension() : Str::after(mime_content_type($file), '/');
24
    }
25
26
    private function getFileName(string|UploadedFile $file): string
27
    {
28
        if (is_file($file)) {
29
            return Str::of($file->getClientOriginalName())->beforeLast('.')->slug()->append('-'.Str::random(4));
30
        }
31
32
        return Str::random(40);
33
    }
34
}
35