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
27:47 queued 12:50
created

SingleFile::uploadRepeatableFile()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 13
nc 9
nop 2
dl 0
loc 25
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Uploads\Uploaders;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\Storage;
8
9
class SingleFile extends Uploader
10
{
11
    public function uploadRepeatableFile(Model $entry, $values = null)
12
    {
13
        $orderedFiles = $this->getFileOrderFromRequest();
14
15
        $previousFiles = $this->getPreviousRepeatableValues($entry);
16
17
        foreach ($values as $row => $file) {
18
            if ($file && is_file($file) && $file->isValid()) {
19
                $fileName = $this->getFileName($file);
20
21
                $file->storeAs($this->getPath(), $fileName, $this->getDisk());
22
                $orderedFiles[$row] = $this->getPath().$fileName;
23
24
                continue;
25
            }
26
        }
27
28
        foreach ($previousFiles as $row => $file) {
29
            if ($file && ! isset($orderedFiles[$row])) {
30
                $orderedFiles[$row] = null;
31
                Storage::disk($this->getDisk())->delete($file);
32
            }
33
        }
34
35
        return $orderedFiles;
36
    }
37
38
    public function uploadFile(Model $entry, $value = null)
39
    {
40
        $value = $value ?? CrudPanelFacade::getRequest()->file($this->getName());
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on Backpack\CRUD\app\Librar...udPanel\CrudPanelFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

40
        $value = $value ?? CrudPanelFacade::/** @scrutinizer ignore-call */ getRequest()->file($this->getName());
Loading history...
41
42
        $previousFile = $entry->getOriginal($this->getName());
43
44
        if ($value && is_file($value) && $value->isValid()) {
45
            if ($previousFile) {
46
                Storage::disk($this->getDisk())->delete($previousFile);
47
            }
48
            $fileName = $this->getFileName($value);
49
50
            $value->storeAs($this->getPath(), $fileName, $this->getDisk());
51
52
            return $this->getPath().$fileName;
53
        }
54
55
        if (! $value && CrudPanelFacade::getRequest()->has($this->getName()) && $previousFile) {
56
            Storage::disk($this->getDisk())->delete($previousFile);
57
58
            return null;
59
        }
60
61
        return $previousFile;
62
    }
63
}
64