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   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefault() 0 3 2
A getValidationRules() 0 16 6
A getAttributeName() 0 3 1
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