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
28:25 queued 13:22
created

SingleFile::uploadRepeatableFile()   B

Complexity

Conditions 8
Paths 9

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 13
c 0
b 0
f 0
nc 9
nop 2
dl 0
loc 24
rs 8.4444
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
        $previousFiles = $this->getPreviousRepeatableValues($entry);
15
16
        foreach ($values as $row => $file) {
17
            if ($file && is_file($file) && $file->isValid()) {
18
                $fileName = $this->getFileName($file);
19
20
                $file->storeAs($this->getPath(), $fileName, $this->getDisk());
21
22
                $orderedFiles[$row] = $this->getPath().$fileName;
23
                continue;
24
            }
25
        }
26
27
        foreach ($previousFiles as $row => $file) {
28
            if ($file && ! isset($orderedFiles[$row])) {
29
                $orderedFiles[$row] = null;
30
                Storage::disk($this->getDisk())->delete($file);
31
            }
32
        }
33
34
        return $orderedFiles;
35
    }
36
37
    public function uploadFile(Model $entry, $value = null)
38
    {
39
        $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

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