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 ( f5e93a...469ece )
by Pedro
11:36
created

HandleFileNaming   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileName() 0 7 3
A setFileNameGenerator() 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
    /**
11
     * Developer provided filename.
12
     *
13
     * @var null|string|\Closure
14
     */
15
    public $fileName = null;
16
17
    /**
18
     * The file name generator.
19
     *
20
     * @var FileNameGeneratorInterface
21
     */
22
    public $fileNameGenerator;
23
24
    /**
25
     * Returns the file generator class.
26
     *
27
     * @param  null|string  $fileNameGenerator
28
     * @return void
29
     */
30
    private function setFileNameGenerator($fileNameGenerator)
31
    {
32
        $fileGeneratorClass = $fileNameGenerator ?? config('backpack.crud.file_name_generator');
33
34
        if (! class_exists($fileGeneratorClass)) {
35
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] does not exist.");
36
        }
37
38
        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

38
        if (! class_implements($fileGeneratorClass, /** @scrutinizer ignore-type */ FileNameGeneratorInterface::class)) {
Loading history...
39
            throw new \Exception("The file name generator class [{$fileGeneratorClass}] must implement the [".FileNameGeneratorInterface::class.'] interface.');
40
        }
41
42
        $this->fileNameGenerator = new $fileGeneratorClass();
43
    }
44
45
    /**
46
     * Return the file name.
47
     *
48
     * @param  string|UploadedFile  $file
49
     * @return string
50
     */
51
    public function getFileName($file)
52
    {
53
        if ($this->fileName) {
54
            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...
55
        }
56
57
        return $this->fileNameGenerator->generate($file);
58
    }
59
}
60