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 — datagrid ( 50b42e...bbd442 )
by Cristian
18:47
created

ShowComponent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A render() 0 8 2
A setPropertiesFromController() 0 26 5
1
<?php
2
3
namespace Backpack\CRUD\app\View\Components;
4
5
use Backpack\CRUD\CrudManager;
6
use Illuminate\View\Component;
7
use Illuminate\Database\Eloquent\Model;
8
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
9
10
abstract class ShowComponent extends Component
11
{
12
    /**
13
     * Create a new component instance.
14
     */
15
    public function __construct(
16
        public Model $entry,
17
        public ?string $controller = null,
18
        public ?string $operation = 'show',
19
        public ?\Closure $setup = null,
20
        public ?CrudPanel $crud = null,
21
        public array $columns = [],
22
        public bool $displayButtons = true
23
    ) {
24
        $this->setPropertiesFromController();
25
    }
26
27
    /**
28
     * Set properties from the controller context.
29
     *
30
     * This method initializes the CrudPanel and sets the active controller.
31
     * It also applies any setup closure provided.
32
     */
33
    protected function setPropertiesFromController() : void
34
    {
35
        // If no CrudController is provided, do nothing
36
        if (!$this->controller) {
37
            return;
38
        }
39
40
        // If no CrudPanel is provided, try to get it from the CrudManager
41
        $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

41
        $this->crud ??= CrudManager::/** @scrutinizer ignore-call */ setupCrudPanel($this->controller, $this->operation);
Loading history...
42
43
        // Set active controller for proper context
44
        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

44
        CrudManager::/** @scrutinizer ignore-call */ 
45
                     setActiveController($this->controller);
Loading history...
45
46
        // If a setup closure is provided, apply it
47
        if ($this->setup) {
48
            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...
49
                throw new \Exception('You cannot define both setup closure and columns for a ' . class_basename(static::class) . ' component.');
50
            }
51
52
            ($this->setup)($this->crud, $this->entry);
53
        }
54
55
        $this->columns = !empty($columns) ? $columns : $this->crud?->getOperationSetting('columns', $this->operation) ?? [];
56
57
        // Reset the active controller
58
        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

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