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 — crud-uploads (#5038)
by Cristian
26:23 queued 11:26
created

ValidUploadMultiple   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 5
Bugs 2 Features 0
Metric Value
eloc 25
c 5
b 2
f 0
dl 0
loc 57
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 47 8
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Uploaders\Validation;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Backpack\CRUD\app\Library\Validation\Rules\ValidArray;
7
use Closure;
8
9
class ValidUploadMultiple extends ValidArray
10
{
11
    /**
12
     * Run the validation rule.
13
     *
14
     * @param  string  $attribute
15
     * @param  mixed  $value
16
     * @param  \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
17
     * @return void
18
     */
19
    public function validate(string $attribute, mixed $value, Closure $fail): void
20
    {
21
        if (! is_array($value)) {
22
            try {
23
                $value = json_decode($value, true);
24
            } catch(\Exception $e) {
25
                $fail('Unable to determine the value type');
26
27
                return;
28
            }
29
        }
30
31
        // `upload_multiple` sends [[0 => null]] when user doesn't upload anything
32
        // assume that nothing changed on field so nothing is sent on the request.
33
        if (count($value) === 1 && empty($value[0])) {
34
            unset($this->data[$attribute]);
35
            $value = [];
36
        }
37
38
        $previousValues = $this->entry?->{$attribute} ?? [];
39
        if (is_string($previousValues)) {
40
            $previousValues = json_decode($previousValues, true);
41
        }
42
43
        $value = array_merge($previousValues, $value);
44
45
        // if user uploaded something add it to the data beeing validated.
46
        if (! empty($value)) {
47
            $this->data[$attribute] = $value;
48
        }
49
50
        if ($this->entry) {
51
            $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

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