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 ( 044930 )
by Pedro
11:38
created

SingleFile   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 27
c 1
b 0
f 1
dl 0
loc 58
rs 10
wmc 19

3 Methods

Rating   Name   Duplication   Size   Complexity  
B saveFile() 0 24 8
B saveRepeatableFile() 0 25 8
A save() 0 3 3
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 save(Model $entry, $value = null)
12
    {
13
        return $this->isRepeatable && ! $this->isRelationship ? $this->saveRepeatableFile($entry, $value) : $this->saveFile($entry, $value);
14
    }
15
16
    private function saveRepeatableFile($entry, $values)
17
    {
18
        $orderedFiles = $this->getFileOrderFromRequest();
19
20
        $previousFiles = $this->getPreviousRepeatableValues($entry);
21
22
        foreach ($values as $row => $file) {
23
            if ($file && is_file($file) && $file->isValid()) {
24
                $fileName = $this->getFileNameWithExtension($file);
25
26
                $file->storeAs($this->path, $fileName, $this->disk);
27
                $orderedFiles[$row] = $this->path.$fileName;
28
29
                continue;
30
            }
31
        }
32
33
        foreach ($previousFiles as $row => $file) {
34
            if ($file && ! isset($orderedFiles[$row])) {
35
                $orderedFiles[$row] = null;
36
                Storage::disk($this->disk)->delete($file);
37
            }
38
        }
39
40
        return $orderedFiles;
41
    }
42
43
    private function saveFile($entry, $value)
44
    {
45
        $value = $value ?? CrudPanelFacade::getRequest()->file($this->name);
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

45
        $value = $value ?? CrudPanelFacade::/** @scrutinizer ignore-call */ getRequest()->file($this->name);
Loading history...
46
47
        $previousFile = $entry->getOriginal($this->name);
48
49
        if ($value && is_file($value) && $value->isValid()) {
50
            if ($previousFile) {
51
                Storage::disk($this->disk)->delete($previousFile);
52
            }
53
            $fileName = $this->getFileNameWithExtension($value);
54
55
            $value->storeAs($this->path, $fileName, $this->disk);
56
57
            return $this->path.$fileName;
58
        }
59
60
        if (! $value && CrudPanelFacade::getRequest()->has($this->name) && $previousFile) {
61
            Storage::disk($this->disk)->delete($previousFile);
62
63
            return null;
64
        }
65
66
        return $previousFile;
67
    }
68
}
69