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 Failed
Pull Request — main (#5518)
by Pedro
34:25 queued 23:25
created

ValidUpload   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 8
Bugs 7 Features 0
Metric Value
eloc 18
c 8
b 7
f 0
dl 0
loc 44
rs 10
wmc 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A field() 0 3 1
B validateRules() 0 34 11
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Validation\Rules;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade;
6
use Illuminate\Contracts\Validation\Rule;
7
use Illuminate\Contracts\Validation\ValidationRule;
8
use Illuminate\Http\UploadedFile;
9
use Illuminate\Support\Arr;
10
use Illuminate\Support\Str;
11
12
class ValidUpload extends BackpackCustomRule
13
{
14
    /**
15
     * Run the validation rule and return the array of errors.
16
     */
17
    public function validateRules(string $attribute, mixed $value): array
18
    {
19
        $entry = CrudPanelFacade::getCurrentEntry();
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

19
        /** @scrutinizer ignore-call */ 
20
        $entry = CrudPanelFacade::getCurrentEntry();
Loading history...
20
21
        // if the attribute is not set in the request, and an entry exists,
22
        // we will check if there is a previous value, as this field might not have changed.
23
        if (! Arr::has($this->data, $attribute) && $entry) {
24
            if (str_contains($attribute, '.') && get_class($entry) === get_class(CrudPanelFacade::getModel())) {
0 ignored issues
show
Bug introduced by
The method getModel() 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

24
            if (str_contains($attribute, '.') && get_class($entry) === get_class(CrudPanelFacade::/** @scrutinizer ignore-call */ getModel())) {
Loading history...
25
                $previousValue = Arr::get($this->data, '_order_'.Str::before($attribute, '.'));
26
                $previousValue = Arr::get($previousValue, Str::after($attribute, '.'));
27
            } else {
28
                $previousValue = Arr::get($entry, $attribute);
29
            }
30
31
            if ($previousValue && empty($value)) {
32
                return [];
33
            }
34
35
            Arr::set($this->data, $attribute, $previousValue ?? $value);
36
        }
37
38
        // if the value is an uploaded file, or the attribute is not
39
        // set in the request, we force fill the data with the value
40
        if ($value instanceof UploadedFile || ! Arr::has($this->data, $attribute)) {
41
            Arr::set($this->data, $attribute, $value);
42
        }
43
44
        $fieldErrors = $this->validateFieldRules($attribute);
45
46
        if (! empty($value) && ! empty($this->getFileRules())) {
47
            $fileErrors = $this->validateFileRules($attribute, $value);
48
        }
49
50
        return array_merge($fieldErrors, $fileErrors ?? []);
51
    }
52
53
    public static function field(string|array|ValidationRule|Rule $rules = []): self
54
    {
55
        return parent::field($rules);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::field($rules) returns the type Backpack\CRUD\app\Librar...ules\BackpackCustomRule which includes types incompatible with the type-hinted return Backpack\CRUD\app\Librar...ation\Rules\ValidUpload.
Loading history...
56
    }
57
}
58