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 ( 997beb...192cbc )
by Pedro
15:02
created

BaseComponent   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 5 1
A remove() 0 3 1
A blocked() 0 3 1
A __call() 0 10 3
A rules() 0 3 1
A isAttributeBlocked() 0 3 1
A __construct() 0 2 1
A makeOf() 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
8
class BaseComponent implements SmartComponentInterface
9
{
10
    public function __construct(protected SmartCollectionInterface $attributes)
11
    {
12
    }
13
14
    public static function makeOf(SmartCollectionInterface $attributes)
15
    {
16
        return new static($attributes);
17
    }
18
19
    public static function make(string|array $name): SmartComponentInterface
20
    {
21
        $attributes = new BaseCollection($name, static::attributes(), static::rules(), static::defaults(), static::blocked());
22
23
        return  static::makeOf($attributes);
24
    }
25
26
    protected function remove()
27
    {
28
        $this->attributes->deleteItem($this->getName());
0 ignored issues
show
Bug introduced by
$this->getName() of type Backpack\CRUD\app\Librar...ents\BaseComponent|null is incompatible with the type string expected by parameter $name of Backpack\CRUD\app\Librar...Interface::deleteItem(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        $this->attributes->deleteItem(/** @scrutinizer ignore-type */ $this->getName());
Loading history...
Bug introduced by
The method getName() does not exist on Backpack\CRUD\app\Library\Components\BaseComponent. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->attributes->deleteItem($this->/** @scrutinizer ignore-call */ getName());
Loading history...
29
    }
30
31
    public function __call($name, $arguments)
32
    {
33
        if (! method_exists($this, $name)) {
34
            if ($this->isAttributeBlocked($name)) {
35
                throw new \Exception("Attribute {$name} cannot be changed in this component.");
36
            }
37
38
            $this->attributes->setAttribute($name, $arguments[0] ?? null);
39
40
            return $this;
41
        }
42
    }
43
44
    private function isAttributeBlocked(string $attribute): bool
45
    {
46
        return in_array($attribute, $this->blocked());
47
    }
48
49
    public static function defaults(): array
50
    {
51
        return static::attributes();
52
    }
53
54
    public static function rules(): array
55
    {
56
        return static::attributes();
57
    }
58
59
    public static function blocked(): array
60
    {
61
        return static::attributes();
62
    }
63
64
    public static function attributes(): array
65
    {
66
        return [];
67
    }
68
}
69