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 ( c657db...bf972d )
by Pedro
13:12
created

HandleFileNaming::getFileName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Uploads\Traits;
4
use Illuminate\Http\UploadedFile;
5
use Backpack\CRUD\app\Library\CrudPanel\Uploads\Support\Interfaces\FileNameGeneratorInterface;
6
7
trait HandleFileNaming
8
{
9
    /**
10
     * Developer provided filename.
11
     *
12
     * @var null|string|\Closure
13
     */
14
    public $fileName = null;
15
16
    /**
17
     * The file name generator.
18
     * @var FileNameGeneratorInterface
19
     */
20
    public $fileNameGenerator;
21
22
    /**
23
     * Returns the file generator class
24
     *
25
     * @param null|string $fileNameGenerator
26
     * @return void
27
     */
28
    private function setFileNameGenerator($fileNameGenerator)
29
    {
30
        $fileGeneratorClass = $fileNameGenerator ?? config('backpack.crud.file_name_generator');
31
32
        if (! class_exists($fileGeneratorClass)) {
33
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] does not exist.");
34
        }
35
36
        if(! class_implements($fileGeneratorClass, FileNameGeneratorInterface::class)) {
0 ignored issues
show
Bug introduced by
Backpack\CRUD\app\Librar...neratorInterface::class of type string is incompatible with the type boolean expected by parameter $autoload of class_implements(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        if(! class_implements($fileGeneratorClass, /** @scrutinizer ignore-type */ FileNameGeneratorInterface::class)) {
Loading history...
37
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] must implement the [".FileNameGeneratorInterface::class."] interface.");
38
        }
39
        
40
        $this->fileNameGenerator = new $fileGeneratorClass();
41
    }
42
43
    /**
44
     * Return the file name
45
     *
46
     * @param string|UploadedFile $file
47
     * @return string
48
     */
49
    public function getFileName($file) {
50
        if($this->fileName) {
51
            return is_callable($this->fileName) ? ($this->fileName)($file, $this) : $this->fileName;
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_callable($this...this) : $this->fileName also could return the type Closure which is incompatible with the documented return type string.
Loading history...
52
        }
53
54
        return $this->fileNameGenerator->generate($file);
55
    }
56
57
}