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   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 64
rs 10
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 3 1
A getDefault() 0 3 1
A setRules() 0 3 1
A setValue() 0 7 1
A getAttributeName() 0 3 1
A name() 0 3 1
A make() 0 3 1
A getValidationRules() 0 3 1
A __construct() 0 5 1
A validate() 0 6 2
A value() 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
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