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 — add-form-component ( 97e7ab...44b9fd )
by Cristian
33:25 queued 15:38
created

ShowComponent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 7
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Backpack\CRUD\app\View\Components;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
6
use Backpack\CRUD\CrudManager;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Collection;
9
use Illuminate\View\Component;
10
11
abstract class ShowComponent extends Component
12
{
13
    /**
14
     * Create a new component instance.
15
     */
16
    public function __construct(
17
        public Model $entry,
18
        public ?string $controller = null,
19
        public ?string $operation = 'show',
20
        public ?\Closure $setup = null,
21
        public ?CrudPanel $crud = null,
22
        public array|Collection $columns = [],
23
        public bool $displayButtons = true
24
    ) {
25
        $this->setPropertiesFromController();
26
    }
27
28
    /**
29
     * Set properties from the controller context.
30
     *
31
     * This method initializes the CrudPanel and sets the active controller.
32
     * It also applies any setup closure provided.
33
     */
34
    protected function setPropertiesFromController(): void
35
    {
36
        // If no CrudController is provided, do nothing
37
        if (! $this->controller) {
38
            return;
39
        }
40
41
        // If no CrudPanel is provided, try to get it from the CrudManager
42
        $this->crud ??= CrudManager::setupCrudPanel($this->controller, $this->operation);
0 ignored issues
show
Bug introduced by
The method setupCrudPanel() does not exist on Backpack\CRUD\CrudManager. Since you implemented __callStatic, 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

42
        $this->crud ??= CrudManager::/** @scrutinizer ignore-call */ setupCrudPanel($this->controller, $this->operation);
Loading history...
43
44
        // Set active controller for proper context
45
        CrudManager::setActiveController($this->controller);
0 ignored issues
show
Bug introduced by
The method setActiveController() does not exist on Backpack\CRUD\CrudManager. Since you implemented __callStatic, 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

45
        CrudManager::/** @scrutinizer ignore-call */ 
46
                     setActiveController($this->controller);
Loading history...
46
47
        // If a setup closure is provided, apply it
48
        if ($this->setup) {
49
            if (! empty($columns)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $columns seems to never exist and therefore empty should always be true.
Loading history...
50
                throw new \Exception('You cannot define both setup closure and columns for a '.class_basename(static::class).' component.');
51
            }
52
53
            ($this->setup)($this->crud, $this->entry);
54
        }
55
56
        $this->columns = ! empty($columns) ? $columns : $this->crud?->getOperationSetting('columns', $this->operation) ?? [];
57
58
        // Reset the active controller
59
        CrudManager::unsetActiveController();
0 ignored issues
show
Bug introduced by
The method unsetActiveController() does not exist on Backpack\CRUD\CrudManager. Since you implemented __callStatic, 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

59
        CrudManager::/** @scrutinizer ignore-call */ 
60
                     unsetActiveController();
Loading history...
60
    }
61
62
    /**
63
     * Get the view name for the component.
64
     * This method must be implemented by child classes.
65
     */
66
    abstract protected function getViewName(): string;
67
68
    /**
69
     * Get the view / contents that represent the component.
70
     */
71
    public function render()
72
    {
73
        // if no columns are set, don't load any view
74
        if (empty($this->columns)) {
75
            return '';
76
        }
77
78
        return view($this->getViewName());
79
    }
80
}
81