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

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
8
trait HandleFileNaming
9
{
10
    public ?string $fileName = null;
11
12
    public FileNameGeneratorInterface $fileNameGenerator;
13
14
    public function getFileName(string|UploadedFile $file): string
15
    {
16
        if ($this->fileName) {
17
            return is_callable($this->fileName) ? ($this->fileName)($file, $this) : $this->fileName;
18
        }
19
20
        return $this->fileNameGenerator->getName($file);
21
    }
22
23
    private function getFileNameGeneratorInstance(?string $fileNameGenerator): FileNameGeneratorInterface
24
    {
25
        $fileGeneratorClass = $fileNameGenerator ?? config('backpack.crud.file_name_generator');
26
27
        if (! class_exists($fileGeneratorClass)) {
28
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] does not exist.");
29
        }
30
31
        if (! in_array(FileNameGeneratorInterface::class, class_implements($fileGeneratorClass, false))) {
32
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] must implement the [".FileNameGeneratorInterface::class.'] interface.');
33
        }
34
35
        return new $fileGeneratorClass();
36
    }
37
}
38