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 — fix-uploads-in-relationship-re... ( 29b535 )
by Pedro
14:55
created

SingleFile::shouldKeepPreviousValueUnchanged()   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 2
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
            return null;
19
        }
20
21
        if ($value && is_file($value) && $value->isValid()) {
22
            if ($previousFile) {
23
                Storage::disk($this->getDisk())->delete($previousFile);
24
            }
25
            $fileName = $this->getFileName($value);
26
            $value->storeAs($this->getPath(), $fileName, $this->getDisk());
27
28
            return $this->getPath().$fileName;
29
        }
30
31
        if (! $value && CrudPanelFacade::getRequest()->has($this->getNameForRequest()) && $previousFile) {
32
            Storage::disk($this->getDisk())->delete($previousFile);
33
34
            return null;
35
        }
36
        return $previousFile;
37
    }
38
39
    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

39
    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...
40
    {
41
        $orderedFiles = $this->getFileOrderFromRequest();
42
43
        foreach ($values as $row => $file) {
44
            if ($file && is_file($file) && $file->isValid()) {
45
                $fileName = $this->getFileName($file);
46
                $file->storeAs($this->getPath(), $fileName, $this->getDisk());
47
                $orderedFiles[$row] = $this->getPath().$fileName;
48
49
                continue;
50
            }
51
        }
52
53
        foreach ($previousRepeatableValues as $row => $file) {
54
            if ($file && ! isset($orderedFiles[$row])) {
55
                $orderedFiles[$row] = null;
56
                Storage::disk($this->getDisk())->delete($file);
57
            }
58
        }
59
60
        return $orderedFiles;
61
    }
62
63
    /**
64
     * Single file uploaders send no value when they are not dirty
65
     */
66
    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

66
    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...
67
    {
68
        return is_string($entryValue);
69
    }
70
71
    protected function hasDeletedFiles($entryValue): bool
72
    {
73
        return $entryValue === null;
74
    }
75
76
    protected function shouldUploadFiles($value): bool
77
    {
78
        return is_a($value, 'Illuminate\Http\UploadedFile', true);
79
    }
80
}
81