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

ValidUploadMultiple   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 5
Bugs 3 Features 0
Metric Value
eloc 24
dl 0
loc 54
rs 10
c 5
b 3
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 44 8
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Validation\Rules;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Closure;
7
8
class ValidUploadMultiple extends ValidFileArray
9
{
10
    /**
11
     * Run the validation rule.
12
     *
13
     * @param  string  $attribute
14
     * @param  mixed  $value
15
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
16
     * @return void
17
     */
18
    public function validate(string $attribute, mixed $value, Closure $fail): void
19
    {
20
        if (! $value = self::ensureValidValue($value)) {
21
            $fail('Unable to determine the value type.');
22
23
            return;
24
        }
25
26
        $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

26
        $entry = CrudPanelFacade::/** @scrutinizer ignore-call */ getCurrentEntry() !== false ? CrudPanelFacade::getCurrentEntry() : null;
Loading history...
27
28
        // `upload_multiple` sends [[0 => null]] when user doesn't upload anything
29
        // assume that nothing changed on field so nothing is sent on the request.
30
        if (count($value) === 1 && empty($value[0])) {
31
            if ($entry) {
32
                unset($this->data[$attribute]);
33
            } else {
34
                $this->data[$attribute] = [];
35
            }
36
            $value = [];
37
        }
38
39
        $previousValues = $entry?->{$attribute} ?? [];
40
        if (is_string($previousValues)) {
41
            $previousValues = json_decode($previousValues, true) ?? [];
42
        }
43
44
        $value = array_merge($previousValues, $value);
0 ignored issues
show
Bug introduced by
It seems like $value can also be of type false; however, parameter $arrays of array_merge() 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

44
        $value = array_merge($previousValues, /** @scrutinizer ignore-type */ $value);
Loading history...
45
46
        if ($entry) {
47
            $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

47
            $filesDeleted = CrudPanelFacade::/** @scrutinizer ignore-call */ getRequest()->input('clear_'.$attribute) ?? [];
Loading history...
48
49
            $data = $this->data;
50
            $data[$attribute] = array_diff($value, $filesDeleted);
51
52
            $this->validateArrayData($attribute, $fail, $data);
53
54
            $this->validateItems($attribute, $value, $fail);
55
56
            return;
57
        }
58
59
        $this->validateArrayData($attribute, $fail);
60
61
        $this->validateItems($attribute, $value, $fail);
62
    }
63
}
64