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

BaseComponent::hasAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Backpack\CRUD\app\Library\Components;
4
5
use Backpack\CRUD\app\Library\Components\Interfaces\SmartCollectionInterface;
6
use Backpack\CRUD\app\Library\Components\Interfaces\SmartComponentInterface;
7
use Illuminate\Support\Collection;
8
9
class BaseComponent implements SmartComponentInterface
10
{
11
    public function __construct(protected SmartCollectionInterface $attributes)
12
    {
13
    }
14
15
    public static function makeOf(SmartCollectionInterface $attributes)
16
    {
17
        return new static($attributes);
18
    }
19
20
    public function getAttributes(): Collection
21
    {
22
        return $this->attributes->getAttributes();
23
    }
24
25
    public static function make(string|array $name): SmartComponentInterface
26
    {
27
        $attributes = new BaseCollection($name, static::attributes(), static::rules(), static::defaults(), static::blocked());
28
29
        return  static::makeOf($attributes);
30
    }
31
32
    protected function remove()
33
    {
34
        $this->attributes->deleteItem($this->getName());
35
    }
36
37
    public function getName(): string
38
    {
39
        return $this->attributes->getAttributeValue('name');
40
    }
41
42
    public function hasAttribute(string $attribute): bool
43
    {
44
        return $this->attributes->hasAttribute($attribute);
45
    }
46
47
    public function getAttribute(string $attribute)
48
    {
49
        return $this->attributes->getAttributeValue($attribute);
50
    }
51
52
    public function __call($name, $arguments)
53
    {
54
        if (! method_exists($this, $name)) {
55
            if ($this->isAttributeBlocked($name)) {
56
                throw new \Exception("Attribute {$name} cannot be changed in this component.");
57
            }
58
59
            $this->attributes->setAttribute($name, $arguments[0] ?? null);
60
61
            return $this;
62
        }
63
    }
64
65
    private function isAttributeBlocked(string $attribute): bool
66
    {
67
        return in_array($attribute, $this->blocked());
68
    }
69
70
    public static function defaults(): array
71
    {
72
        return static::attributes();
73
    }
74
75
    public static function rules(): array
76
    {
77
        return static::attributes();
78
    }
79
80
    public static function blocked(): array
81
    {
82
        return static::attributes();
83
    }
84
85
    public static function attributes(): array
86
    {
87
        return [];
88
    }
89
}
90