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 — upload-validation ( 199e68...d8ff11 )
by Pedro
11:25
created

ValidUploadMultiple::validate()   B

Complexity

Conditions 8
Paths 33

Size

Total Lines 47
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 8
eloc 24
c 3
b 1
f 0
nc 33
nop 3
dl 0
loc 47
rs 8.4444
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Uploaders\Validation;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Closure;
7
8
class ValidUploadMultiple extends ValidBackpackUpload
0 ignored issues
show
Bug introduced by
The type Backpack\CRUD\app\Librar...ion\ValidBackpackUpload was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 (! is_array($value)) {
21
            try {
22
                $value = json_decode($value, true);
23
            } catch(\Exception $e) {
24
                $fail('Unable to determine the value type');
25
26
                return;
27
            }
28
        }
29
30
        // `upload_multiple` sends [[0 => null]] when user doesn't upload anything
31
        // assume that nothing changed on field so nothing is sent on the request.
32
        if (count($value) === 1 && empty($value[0])) {
33
            unset($this->data[$attribute]);
34
            $value = [];
35
        }
36
                   
37
        $previousValues = $this->entry?->{$attribute} ?? [];
38
        if (is_string($previousValues)) {
39
            $previousValues = json_decode($previousValues, true);
40
        }
41
42
        $value = array_merge($previousValues, $value);
43
44
        // if user uploaded something add it to the data beeing validated.
45
        if(!empty($value)) {
46
            $this->data[$attribute] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
47
        }
48
       
49
        if ($this->entry) {
50
            $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

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