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

ValidUpload   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
eloc 14
dl 0
loc 38
rs 10
c 4
b 2
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validate() 0 18 7
A field() 0 3 1
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\HasFiles;
7
use Closure;
8
use Illuminate\Contracts\Validation\Rule;
9
use Illuminate\Contracts\Validation\ValidationRule;
10
use Illuminate\Support\Facades\Validator;
11
12
class ValidUpload extends BackpackCustomRule
13
{
14
    use HasFiles;
15
16
    /**
17
     * Run the validation rule.
18
     *
19
     * @param  string  $attribute
20
     * @param  mixed  $value
21
     * @param  Closure(string): \Illuminate\Translation\PotentiallyTranslatedString  $fail
22
     * @return void
23
     */
24
    public function validate(string $attribute, mixed $value, Closure $fail): void
25
    {
26
        $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

26
        /** @scrutinizer ignore-call */ 
27
        $entry = CrudPanelFacade::getCurrentEntry();
Loading history...
27
28
        if (! array_key_exists($attribute, $this->data) && $entry) {
29
            return;
30
        }
31
32
        $this->validateFieldRules($attribute, $value, $fail);
33
34
        if (! empty($value) && ! empty($this->getFileRules())) {
35
            $validator = Validator::make([$attribute => $value], [
36
                $attribute => $this->getFileRules(),
37
            ], $this->validator->customMessages, $this->validator->customAttributes);
0 ignored issues
show
Bug introduced by
Accessing customAttributes on the interface Illuminate\Contracts\Validation\Validator suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Bug introduced by
Accessing customMessages on the interface Illuminate\Contracts\Validation\Validator suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
39
            if ($validator->fails()) {
40
                foreach ($validator->errors()->messages()[$attribute] as $message) {
41
                    $fail($message)->translate();
42
                }
43
            }
44
        }
45
    }
46
47
    public static function field(string|array|ValidationRule|Rule $rules = []): self
48
    {
49
        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...
50
    }
51
}
52