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 (#5422)
by Cristian
37:08 queued 26:15
created

SingleFile::shouldUploadFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\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 uploadFiles(Model $entry, $value = null)
12
    {
13
        $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

13
        $value = $value ?? CrudPanelFacade::/** @scrutinizer ignore-call */ getRequest()->file($this->getName());
Loading history...
14
        $previousFile = $this->getPreviousFiles($entry);
15
16
        if ($value === false && $previousFile) {
17
            Storage::disk($this->getDisk())->delete($previousFile);
18
19
            return null;
20
        }
21
22
        if ($value && is_file($value) && $value->isValid()) {
23
            if ($previousFile) {
24
                Storage::disk($this->getDisk())->delete($previousFile);
25
            }
26
            $fileName = $this->getFileName($value);
27
            $value->storeAs($this->getPath(), $fileName, $this->getDisk());
28
29
            return $this->getPath().$fileName;
30
        }
31
32
        if (! $value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) {
33
            Storage::disk($this->getDisk())->delete($previousFile);
34
35
            return null;
36
        }
37
38
        return $previousFile;
39
    }
40
41
    public function uploadRepeatableFiles($values, $previousRepeatableValues, $entry = null)
0 ignored issues
show
Unused Code introduced by
The parameter $entry is not used and could be removed. ( Ignorable by Annotation )

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

41
    public function uploadRepeatableFiles($values, $previousRepeatableValues, /** @scrutinizer ignore-unused */ $entry = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        $orderedFiles = $this->getFileOrderFromRequest();
44
45
        foreach ($values as $row => $file) {
46
            if ($file && is_file($file) && $file->isValid()) {
47
                $fileName = $this->getFileName($file);
48
                $file->storeAs($this->getPath(), $fileName, $this->getDisk());
49
                $orderedFiles[$row] = $this->getPath().$fileName;
50
51
                continue;
52
            }
53
        }
54
55
        foreach ($previousRepeatableValues as $row => $file) {
56
            if ($file && ! isset($orderedFiles[$row])) {
57
                $orderedFiles[$row] = null;
58
                Storage::disk($this->getDisk())->delete($file);
59
            }
60
        }
61
62
        return $orderedFiles;
63
    }
64
65
    /**
66
     * Single file uploaders send no value when they are not dirty.
67
     */
68
    protected function shouldKeepPreviousValueUnchanged(Model $entry, $entryValue): bool
0 ignored issues
show
Unused Code introduced by
The parameter $entry is not used and could be removed. ( Ignorable by Annotation )

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

68
    protected function shouldKeepPreviousValueUnchanged(/** @scrutinizer ignore-unused */ Model $entry, $entryValue): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        return is_string($entryValue);
71
    }
72
73
    protected function hasDeletedFiles($entryValue): bool
74
    {
75
        return $entryValue === null;
76
    }
77
78
    protected function shouldUploadFiles($value): bool
79
    {
80
        return is_a($value, 'Illuminate\Http\UploadedFile', true);
81
    }
82
}
83