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 — create-setup-cache-class ( d50094 )
by Pedro
15:35
created

Datatable::initializeOperations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\View\Components;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel;
6
use Backpack\CRUD\app\Library\Support\DatatableCache;
7
use Backpack\CRUD\CrudManager;
8
use Illuminate\View\Component;
9
10
class Datatable extends Component
11
{
12
    protected string $tableId;
13
14
    public function __construct(
15
        private string $controller,
16
        private ?CrudPanel $crud = null,
17
        private bool $modifiesUrl = false,
18
        private ?\Closure $setup = null,
19
        private ?string $name = null,
20
    ) {
21
        // Set active controller for proper context
22
        CrudManager::setActiveController($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

22
        CrudManager::/** @scrutinizer ignore-call */ 
23
                     setActiveController($controller);
Loading history...
23
24
        $this->crud ??= CrudManager::setupCrudPanel($controller, 'list');
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

24
        $this->crud ??= CrudManager::/** @scrutinizer ignore-call */ setupCrudPanel($controller, 'list');
Loading history...
25
26
        $this->tableId = $this->generateTableId();
27
28
        if ($this->setup) {
29
            // Apply the configuration using DatatableCache
30
            $cache = DatatableCache::instance();
31
            $cache->applySetupClosure($this->crud, $this->controller, $this->setup, $this->getParentCrudEntry());
0 ignored issues
show
Bug introduced by
It seems like $this->crud can also be of type null; however, parameter $crud of Backpack\CRUD\app\Librar...he::applySetupClosure() does only seem to accept Backpack\CRUD\app\Library\CrudPanel\CrudPanel, maybe add an additional type check? ( Ignorable by Annotation )

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

31
            $cache->applySetupClosure(/** @scrutinizer ignore-type */ $this->crud, $this->controller, $this->setup, $this->getParentCrudEntry());
Loading history...
32
            
33
            // Cache the setup for later use
34
            $cache->cacheForComponent($this->tableId, $this->controller, $this->setup, $this->name, $this->crud);
35
        }
36
37
        if (! $this->crud->has('list.datatablesUrl')) {
0 ignored issues
show
Bug introduced by
The method has() does not exist on null. ( Ignorable by Annotation )

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

37
        if (! $this->crud->/** @scrutinizer ignore-call */ has('list.datatablesUrl')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
            $this->crud->set('list.datatablesUrl', $this->crud->getRoute());
39
        }
40
41
        // Reset the active controller
42
        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

42
        CrudManager::/** @scrutinizer ignore-call */ 
43
                     unsetActiveController();
Loading history...
43
    }
44
45
    private function getParentCrudEntry()
46
    {
47
        $cruds = CrudManager::getCrudPanels();
0 ignored issues
show
Bug introduced by
The method getCrudPanels() 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

47
        /** @scrutinizer ignore-call */ 
48
        $cruds = CrudManager::getCrudPanels();
Loading history...
48
        $parentCrud = reset($cruds);
49
50
        if ($parentCrud && $parentCrud->getCurrentEntry()) {
51
            CrudManager::storeInitializedOperation(
0 ignored issues
show
Bug introduced by
The method storeInitializedOperation() 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

51
            CrudManager::/** @scrutinizer ignore-call */ 
52
                         storeInitializedOperation(
Loading history...
52
                $parentCrud->controller,
53
                $parentCrud->getCurrentOperation()
54
            );
55
56
            return $parentCrud->getCurrentEntry();
57
        }
58
59
        return null;
60
    }
61
62
    private function generateTableId(): string
63
    {
64
        $controllerPart = str_replace('\\', '_', $this->controller);
65
        $namePart = $this->name ?? 'default';
66
        $uniqueId = md5($controllerPart.'_'.$namePart);
67
68
        return 'crudTable_'.$uniqueId;
69
    }
70
71
    public function render()
72
    {
73
        return view('crud::components.datatable.datatable', [
74
            'crud' => $this->crud,
75
            'modifiesUrl' => $this->modifiesUrl,
76
            'tableId' => $this->tableId,
77
        ]);
78
    }
79
}