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 Cristian
40:57 queued 26:46
created

BaseAttribute::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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