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 ( 0ddd2c...dbc69d )
by Pedro
26:57
created

BaseComponent   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 16

14 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 3 1
A make() 0 5 1
A blocked() 0 3 1
A getName() 0 3 1
A __call() 0 10 3
A rules() 0 3 1
A hasAttribute() 0 3 1
A isAttributeBlocked() 0 3 1
A getAttributes() 0 3 1
A __construct() 0 1 1
A makeOf() 0 3 1
A getAttribute() 0 3 1
A defaults() 0 3 1
A attributes() 0 3 1
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
    public static function makeOf(SmartCollectionInterface $attributes)
14
    {
15
        return new static($attributes);
16
    }
17
18
    public function getAttributes(): Collection
19
    {
20
        return $this->attributes->getAttributes();
21
    }
22
23
    public static function make(string|array $name): SmartComponentInterface
24
    {
25
        $attributes = new BaseCollection($name, static::attributes(), static::rules(), static::defaults(), static::blocked());
26
27
        return  static::makeOf($attributes);
28
    }
29
30
    protected function remove()
31
    {
32
        $this->attributes->deleteItem($this->getName());
33
    }
34
35
    public function getName(): string
36
    {
37
        return $this->attributes->getAttributeValue('name');
38
    }
39
40
    public function hasAttribute(string $attribute): bool
41
    {
42
        return $this->attributes->hasAttribute($attribute);
43
    }
44
45
    public function getAttribute(string $attribute)
46
    {
47
        return $this->attributes->getAttributeValue($attribute);
48
    }
49
50
    public function __call($name, $arguments)
51
    {
52
        if (! method_exists($this, $name)) {
53
            if ($this->isAttributeBlocked($name)) {
54
                throw new \Exception("Attribute {$name} cannot be changed in this component.");
55
            }
56
57
            $this->attributes->setAttribute($name, $arguments[0] ?? null);
58
59
            return $this;
60
        }
61
    }
62
63
    private function isAttributeBlocked(string $attribute): bool
64
    {
65
        return in_array($attribute, $this->blocked());
66
    }
67
68
    public static function defaults(): array
69
    {
70
        return static::attributes();
71
    }
72
73
    public static function rules(): array
74
    {
75
        return static::attributes();
76
    }
77
78
    public static function blocked(): array
79
    {
80
        return static::attributes();
81
    }
82
83
    public static function attributes(): array
84
    {
85
        return [];
86
    }
87
}
88