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

HandleFileNaming   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileName() 0 7 3
A getFileNameGeneratorInstance() 0 13 3
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Uploaders\Support\Traits;
4
5
use Backpack\CRUD\app\Library\Uploaders\Support\Interfaces\FileNameGeneratorInterface;
6
use Illuminate\Http\UploadedFile;
7
use Symfony\Component\HttpFoundation\File\File;
8
9
trait HandleFileNaming
10
{
11
    public ?string $fileName = null;
12
13
    public FileNameGeneratorInterface $fileNameGenerator;
14
15
    public function getFileName(string|UploadedFile|File $file): string
16
    {
17
        if ($this->fileName) {
18
            return is_callable($this->fileName) ? ($this->fileName)($file, $this) : $this->fileName;
19
        }
20
21
        return $this->fileNameGenerator->getName($file);
22
    }
23
24
    private function getFileNameGeneratorInstance(?string $fileNameGenerator): FileNameGeneratorInterface
25
    {
26
        $fileGeneratorClass = $fileNameGenerator ?? config('backpack.crud.file_name_generator');
27
28
        if (! class_exists($fileGeneratorClass)) {
29
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] does not exist.");
30
        }
31
32
        if (! in_array(FileNameGeneratorInterface::class, class_implements($fileGeneratorClass, false))) {
33
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] must implement the [".FileNameGeneratorInterface::class.'] interface.');
34
        }
35
36
        return new $fileGeneratorClass();
37
    }
38
}
39