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 ( b93bc1...ad0dd3 )
by Pedro
12:38
created

Form::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Backpack\CRUD\app\View\Components;
4
5
use Backpack\CRUD\CrudManager;
6
use Illuminate\View\Component;
7
8
class Form extends Component
9
{
10
    public $crud;
11
12
    /**
13
     * Create a new component instance.
14
     *
15
     * @param  string  $controller  The CRUD controller class name
16
     * @param  string  $operation  The operation to use (create, update, etc.)
17
     * @param  string|null  $action  Custom form action URL
18
     * @param  string  $method  Form method (post, put, etc.)
19
     */
20
    public function __construct(
21
        public string $controller,
22
        public string $id = 'backpack-form',
23
        public string $operation = 'create',
24
        public ?string $action = null,
25
        public string $method = 'post'
26
    ) {
27
        // Get CRUD panel instance from the controller
28
        $this->crud = CrudManager::setupCrudPanel($controller, $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

28
        /** @scrutinizer ignore-call */ 
29
        $this->crud = CrudManager::setupCrudPanel($controller, $operation);
Loading history...
29
        $this->operation = $operation;
30
        $this->action = $action ?? url($this->crud->route);
0 ignored issues
show
Documentation Bug introduced by
It seems like $action ?? url($this->crud->route) can also be of type Illuminate\Contracts\Routing\UrlGenerator. However, the property $action is declared as type null|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
31
    }
32
33
    /**
34
     * Get the view / contents that represent the component.
35
     *
36
     * @return \Illuminate\Contracts\View\View|\Closure|string
37
     */
38
    public function render()
39
    {
40
        return view('crud::components.form.form', [
41
            'crud' => $this->crud,
42
            'saveAction' => $this->crud->getSaveAction(),
43
            'id' => $this->id,
44
            'operation' => $this->operation,
45
            'action' => $this->action,
46
            'method' => $this->method,
47
        ]);
48
    }
49
}
50