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

Test Setup Failed
Pull Request — main (#5725)
by Pedro
25:49 queued 10:59
created

ValidUploadMultiple::validateRules()   B

Complexity

Conditions 10
Paths 48

Size

Total Lines 35
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 18
c 0
b 0
f 0
nc 48
nop 2
dl 0
loc 35
rs 7.6666

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Backpack\CRUD\app\Library\Validation\Rules;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Backpack\CRUD\app\Library\Validation\Rules\Support\ValidateArrayContract;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Str;
9
10
class ValidUploadMultiple extends BackpackCustomRule implements ValidateArrayContract
11
{
12
    public function validateRules(string $attribute, mixed $value): array
13
    {
14
        $entry = CrudPanelFacade::getCurrentEntry() !== false ? CrudPanelFacade::getCurrentEntry() : null;
0 ignored issues
show
Bug introduced by
The method getCurrentEntry() 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

14
        $entry = CrudPanelFacade::/** @scrutinizer ignore-call */ getCurrentEntry() !== false ? CrudPanelFacade::getCurrentEntry() : null;
Loading history...
15
        $data = $this->data;
16
        // `upload_multiple` sends [[0 => null]] when user doesn't upload anything
17
        // assume that nothing changed on field so nothing is sent on the request.
18
        if (count($value) === 1 && empty($value[0])) {
19
            Arr::set($data, $attribute, []);
20
            $value = [];
21
        }
22
23
        $previousValues = str_contains($attribute, '.') ?
24
                            (Arr::get($entry?->{Str::before($attribute, '.')} ?? [], Str::after($attribute, '.')) ?? []) :
25
                            ($entry?->{$attribute} ?? []);
26
27
        if (is_string($previousValues)) {
28
            $previousValues = json_decode($previousValues, true) ?? [];
29
        }
30
31
        Arr::set($data, $attribute, array_merge($previousValues, $value));
32
33
        if ($entry) {
34
            $filesDeleted = CrudPanelFacade::getRequest()->input('clear_'.$attribute) ?? [];
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

34
            $filesDeleted = CrudPanelFacade::/** @scrutinizer ignore-call */ getRequest()->input('clear_'.$attribute) ?? [];
Loading history...
35
            Arr::set($data, $attribute, array_diff(Arr::get($data, $attribute), $filesDeleted));
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($data, $attribute) can also be of type null; however, parameter $array of array_diff() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

35
            Arr::set($data, $attribute, array_diff(/** @scrutinizer ignore-type */ Arr::get($data, $attribute), $filesDeleted));
Loading history...
36
37
            return $this->validateFieldAndFile($attribute, $data);
38
        }
39
40
        // if there is no entry, the values we are going to validate need to be files
41
        // the request was tampered so we will set the attribute to null
42
        if (! $entry && ! empty(Arr::get($data, $attribute)) && ! $this->allFiles(Arr::get($data, $attribute))) {
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($data, $attribute) can also be of type null; however, parameter $values of Backpack\CRUD\app\Librar...oadMultiple::allFiles() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

42
        if (! $entry && ! empty(Arr::get($data, $attribute)) && ! $this->allFiles(/** @scrutinizer ignore-type */ Arr::get($data, $attribute))) {
Loading history...
43
            Arr::set($data, $attribute, null);
44
        }
45
46
        return $this->validateFieldAndFile($attribute, $data);
47
    }
48
49
    private function allFiles(array $values): bool
50
    {
51
        foreach ($values as $value) {
52
            if (! $value instanceof \Illuminate\Http\UploadedFile) {
53
                return false;
54
            }
55
        }
56
57
        return true;
58
    }
59
}
60