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
Pull Request — main (#5715)
by Cristian
11:33
created

ValidUploadMultiple::validate()   B

Complexity

Conditions 8
Paths 25

Size

Total Lines 44
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 23
nc 25
nop 3
dl 0
loc 44
rs 8.4444
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ValidUploadMultiple::allFiles() 0 9 3
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