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

Test Failed
Push — fix-hooks-at-setup-level ( 61309d...2f89cc )
by Pedro
21:43 queued 06:25
created

LifecycleHooks::trigger()   B

Complexity

Conditions 9
Paths 24

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 9
eloc 13
c 3
b 1
f 0
nc 24
nop 2
dl 0
loc 25
rs 8.0555
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Hooks;
4
5
use Backpack\CRUD\CrudManager;
6
7
final class LifecycleHooks
8
{
9
    public array $hooks = [];
10
    private array $executedHooks = [];
11
12
    public function hookInto(string|array $hooks, callable $callback): void
13
    {
14
        $hooks = is_array($hooks) ? $hooks : [$hooks];
0 ignored issues
show
introduced by
The condition is_array($hooks) is always true.
Loading history...
15
        $controller = CrudManager::getActiveController() ?? CrudManager::getParentController();
0 ignored issues
show
Bug introduced by
The method getParentController() 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

15
        $controller = CrudManager::getActiveController() ?? CrudManager::/** @scrutinizer ignore-call */ getParentController();
Loading history...
Bug introduced by
The method getActiveController() 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

15
        $controller = CrudManager::/** @scrutinizer ignore-call */ getActiveController() ?? CrudManager::getParentController();
Loading history...
16
        foreach ($hooks as $hook) {
17
            $this->hooks[$controller][$hook][] = $callback;
18
        }
19
    }
20
21
    public function trigger(string|array $hooks, array $parameters = []): void
22
    {
23
        $hooks = is_array($hooks) ? $hooks : [$hooks];
0 ignored issues
show
introduced by
The condition is_array($hooks) is always true.
Loading history...
24
        $controller = CrudManager::getActiveController() ?? CrudManager::getParentController();
25
26
        if (! isset($controller)) {
27
            return; // No active controller, nothing to trigger
28
        }
29
        foreach ($hooks as $hook) {
30
            // Create a unique identifier for this controller+hook combination
31
            $hookId = is_string($controller) ? $controller : $controller::class.'::'.$hook;
32
33
            // Skip if this hook has already been executed
34
            if (isset($this->executedHooks[$hookId])) {
35
                continue;
36
            }
37
38
            if (isset($this->hooks[$controller][$hook])) {
39
                foreach ($this->hooks[$controller][$hook] as $callback) {
40
                    if ($callback instanceof \Closure) {
41
                        $callback(...$parameters);
42
                    }
43
                }
44
45
                $this->executedHooks[$hookId] = true;
46
            }
47
        }
48
    }
49
50
    public function has(string $hook): bool
51
    {
52
        $controller = CrudManager::getActiveController() ?? CrudManager::getParentController();
53
54
        return isset($this->hooks[$controller][$hook]);
55
    }
56
}
57