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 ( f5e93a...469ece )
by Pedro
11:36
created

SingleFile   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 16

2 Methods

Rating   Name   Duplication   Size   Complexity  
B uploadFile() 0 23 8
B uploadRepeatableFile() 0 25 8
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 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
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
        $previousFile = $entry->getOriginal($this->getName());
42
43
        if ($value && is_file($value) && $value->isValid()) {
44
            if ($previousFile) {
45
                Storage::disk($this->getDisk())->delete($previousFile);
46
            }
47
            $fileName = $this->getFileName($value);
48
49
            $value->storeAs($this->getPath(), $fileName, $this->getDisk());
50
51
            return $this->getPath().$fileName;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getPath() . $fileName returns the type string which is incompatible with the return type mandated by Backpack\CRUD\app\Librar...Interface::uploadFile() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
52
        }
53
54
        if (! $value && CrudPanelFacade::getRequest()->has($this->getName()) && $previousFile) {
55
            Storage::disk($this->getDisk())->delete($previousFile);
56
57
            return null;
58
        }
59
60
        return $previousFile;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $previousFile also could return the type array which is incompatible with the return type mandated by Backpack\CRUD\app\Librar...Interface::uploadFile() of void.
Loading history...
61
    }
62
}
63