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 — main (#4854)
by Pedro
30:01 queued 14:59
created

Model::getValidationRules()   A

Complexity

Conditions 6
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 11
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 16
rs 9.2222
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Components\Attributes;
4
5
use Backpack\CRUD\app\Library\Components\Interfaces\SmartAttributeInterface;
6
use Backpack\CRUD\app\Library\Components\Interfaces\SmartCollectionInterface;
7
8
class Model extends BaseAttribute implements SmartAttributeInterface
9
{
10
    public static function getDefault(SmartCollectionInterface $attributes)
11
    {
12
        return $attributes->getAttributeValue('relation_type') ? app('crud')->inferFieldModelFromRelationship($attributes->toArray()) : false;
13
    }
14
15
    public static function getValidationRules(SmartCollectionInterface $attributes): array
16
    {
17
        return [
18
            'required',
19
            function ($attribute, $value, $fail) use ($attributes) {
20
                if ($attributes->hasAttribute('entity') && $attributes->getAttributeValue('entity')) {
21
                    if (! is_string($value)) {
22
                        $fail('The '.$attribute.' should be a valid model string.');
23
                    }
24
25
                    if (! is_a($value, 'Illuminate\Database\Eloquent\Model', true)) {
26
                        $fail('The '.$attribute.' should be a valid class that extends Illuminate\Database\Eloquent\Model .');
27
                    }
28
                } else {
29
                    if ($value !== false) {
30
                        $fail('The '.$attribute.' should be either false or a valid class that extends Illuminate\Database\Eloquent\Model.');
31
                    }
32
                }
33
            },
34
        ];
35
    }
36
37
    public static function getAttributeName(): string
38
    {
39
        return 'model';
40
    }
41
}
42