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 — v6-livewire-widget ( bb8951...53543e )
by Pedro
14:58
created

MultipleFiles   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 19

3 Methods

Rating   Name   Duplication   Size   Complexity  
B uploadFiles() 0 31 10
A for() 0 3 1
B uploadRepeatableFiles() 0 24 8
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Uploaders;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
6
use Backpack\CRUD\app\Library\Uploaders\Support\Interfaces\UploaderInterface;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Arr;
9
use Illuminate\Support\Facades\Storage;
10
11
class MultipleFiles extends Uploader
12
{
13
    public static function for(array $field, $configuration): UploaderInterface
14
    {
15
        return (new self($field, $configuration))->multiple();
16
    }
17
18
    public function uploadFiles(Model $entry, $value = null)
19
    {
20
        $filesToDelete = CRUD::getRequest()->get('clear_'.$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

20
        $filesToDelete = CRUD::/** @scrutinizer ignore-call */ getRequest()->get('clear_'.$this->getName());
Loading history...
21
        $value = $value ?? CRUD::getRequest()->file($this->getName());
22
        $previousFiles = $this->getPreviousFiles($entry) ?? [];
23
24
        if (! is_array($previousFiles) && is_string($previousFiles)) {
25
            $previousFiles = json_decode($previousFiles, true);
26
        }
27
28
        if ($filesToDelete) {
29
            foreach ($previousFiles as $previousFile) {
30
                if (in_array($previousFile, $filesToDelete)) {
31
                    Storage::disk($this->getDisk())->delete($previousFile);
32
33
                    $previousFiles = Arr::where($previousFiles, function ($value, $key) use ($previousFile) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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

33
                    $previousFiles = Arr::where($previousFiles, function ($value, /** @scrutinizer ignore-unused */ $key) use ($previousFile) {

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...
34
                        return $value != $previousFile;
35
                    });
36
                }
37
            }
38
        }
39
40
        foreach ($value ?? [] as $file) {
41
            if ($file && is_file($file)) {
42
                $fileName = $this->getFileName($file);
43
                $file->storeAs($this->getPath(), $fileName, $this->getDisk());
44
                $previousFiles[] = $this->getPath().$fileName;
45
            }
46
        }
47
48
        return isset($entry->getCasts()[$this->getName()]) ? $previousFiles : json_encode($previousFiles);
49
    }
50
51
    public function uploadRepeatableFiles($files, $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

51
    public function uploadRepeatableFiles($files, $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...
52
    {
53
        $fileOrder = $this->getFileOrderFromRequest();
54
55
        foreach ($files as $row => $files) {
0 ignored issues
show
introduced by
$files is overwriting one of the parameters of this function.
Loading history...
56
            foreach ($files ?? [] as $file) {
57
                if ($file && is_file($file)) {
58
                    $fileName = $this->getFileName($file);
59
                    $file->storeAs($this->getPath(), $fileName, $this->getDisk());
60
                    $fileOrder[$row][] = $this->getPath().$fileName;
61
                }
62
            }
63
        }
64
65
        foreach ($previousRepeatableValues as $previousRow => $previousFiles) {
66
            foreach ($previousFiles ?? [] as $key => $file) {
67
                $key = array_search($file, $fileOrder, true);
68
                if ($key === false) {
69
                    Storage::disk($this->getDisk())->delete($file);
70
                }
71
            }
72
        }
73
74
        return $fileOrder;
75
    }
76
}
77