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

BaseAttribute::getDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
use Illuminate\Support\Facades\Validator;
8
9
class BaseAttribute implements SmartAttributeInterface
10
{
11
    public function __construct(
12
                    protected string $name,
13
                    private $value = null,
14
                    private $rules = [],
15
                    private $default = []
16
                ) {
17
    }
18
19
    public static function getValidationRules(SmartCollectionInterface $attributes): array
20
    {
21
        return [];
22
    }
23
24
    public static function make(string $name, $value = null, $rules = [])
25
    {
26
        return new static($name, $value, $rules);
27
    }
28
29
    public static function getDefault(SmartCollectionInterface $attributes)
30
    {
31
        return null;
32
    }
33
34
    public static function getAttributeName(): string
35
    {
36
        return self::$name;
37
    }
38
39
    public function setValue($value)
40
    {
41
        $this->validate($value);
42
43
        $this->value = $value;
44
45
        return $this;
46
    }
47
48
    public function setRules(array $rules)
49
    {
50
        $this->rules = $rules;
51
    }
52
53
    public function rules(): array
54
    {
55
        return $this->rules;
56
    }
57
58
    public function value()
59
    {
60
        return $this->value;
61
    }
62
63
    public function name(): string
64
    {
65
        return $this->name;
66
    }
67
68
    private function validate($value)
69
    {
70
        $validator = Validator::make([$this->name => $value], [$this->name => $this->rules])->stopOnFirstFailure();
71
72
        if ($validator->fails()) {
73
            throw new \Exception($validator->errors()->first());
74
        }
75
    }
76
}
77