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 — poc-backpack-components ( 0c2870...0ddd2c )
by Pedro
23:23
created

BaseAttribute::setRules()   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\AttributeCollection;
6
use Backpack\CRUD\app\Library\Components\Interfaces\AttributeInterface;
7
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
8
use Illuminate\Support\Facades\Validator;
9
10
class BaseAttribute implements AttributeInterface
11
{
12
    public function __construct(
13
                    protected string $name,
14
                    private $value = null,
15
                    private $default = null,
16
                    private $rules = []
17
                ) {
18
    }
19
20
    public static function provider(): CrudPanel
21
    {
22
        return app('crud');
23
    }
24
25
    public static function getValidationRules(): array
26
    {
27
        return [];
28
    }
29
30
    public static function make(string $name, $value = null, $default = [], $rules = [])
31
    {
32
        return new static($name, $value, $default, $rules);
33
    }
34
35
    public static function getDefault(AttributeCollection $attributes)
36
    {
37
        return null;
38
    }
39
40
    public static function getAttributeName(): string
41
    {
42
        return static::$name;
43
    }
44
45
    public function setValue($value)
46
    {
47
        $this->validate($value);
48
49
        $this->value = $value;
50
51
        return $this;
52
    }
53
54
    public function setRules(array $rules)
55
    {
56
        $this->rules = $rules;
57
    }
58
59
    public function rules(): array
60
    {
61
        return $this->rules;
62
    }
63
64
    public function value()
65
    {
66
        return $this->value;
67
    }
68
69
    private function validate($value)
70
    {
71
        $validator = Validator::make([$this->name => $value], [$this->name => $this->rules])->stopOnFirstFailure();
72
73
        if ($validator->fails()) {
74
            throw new \Exception($validator->errors()->first());
75
        }
76
    }
77
}
78