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 ( 5ad161 )
by Pedro
15:49 queued 01:42
created

CreateOperation::setupCreateDefaults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\Operations;
4
5
use Backpack\CRUD\app\Library\CrudPanel\Hooks\Facades\LifecycleHook;
6
use Illuminate\Support\Facades\Route;
7
8
trait CreateOperation
9
{
10
    /**
11
     * Define which routes are needed for this operation.
12
     *
13
     * @param  string  $segment  Name of the current entity (singular). Used as first URL segment.
14
     * @param  string  $routeName  Prefix of the route name.
15
     * @param  string  $controller  Name of the current CrudController.
16
     */
17
    protected function setupCreateRoutes($segment, $routeName, $controller)
18
    {
19
        Route::get($segment.'/create', [
20
            'as' => $routeName.'.create',
21
            'uses' => $controller.'@create',
22
            'operation' => 'create',
23
        ]);
24
25
        Route::post($segment, [
26
            'as' => $routeName.'.store',
27
            'uses' => $controller.'@store',
28
            'operation' => 'create',
29
        ]);
30
31
        Route::get($segment.'/create-form', [
32
            'as' => $routeName.'.create-form',
33
            'uses' => $controller.'@createForm',
34
            'operation' => 'create',
35
        ]);
36
    }
37
38
    /**
39
     * Add the default settings, buttons, etc that this operation needs.
40
     */
41
    protected function setupCreateDefaults()
42
    {
43
        $this->crud->allowAccess('create');
44
45
        LifecycleHook::hookInto('create:before_setup', function () {
0 ignored issues
show
Bug introduced by
The method hookInto() does not exist on Backpack\CRUD\app\Librar...s\Facades\LifecycleHook. 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
        LifecycleHook::/** @scrutinizer ignore-call */ 
46
                       hookInto('create:before_setup', function () {
Loading history...
46
            $this->crud->setupDefaultSaveActions();
47
        });
48
49
        LifecycleHook::hookInto('list:before_setup', function () {
50
            $this->crud->addButton('top', 'create', 'view', 'crud::buttons.create');
51
        });
52
    }
53
54
    /**
55
     * Show the form for creating inserting a new row.
56
     *
57
     * @return \Illuminate\Contracts\View\View
58
     */
59
    public function create()
60
    {
61
        $this->crud->hasAccessOrFail('create');
62
63
        // prepare the fields you need to show
64
        $this->data['crud'] = $this->crud;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
65
        $this->data['saveAction'] = $this->crud->getSaveAction();
66
        $this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.add').' '.$this->crud->entity_name;
67
68
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
69
        return view($this->crud->getCreateView(), $this->data);
70
    }
71
72
    public function createForm()
73
    {
74
        $this->crud->hasAccessOrFail('create');
75
76
        // if the request isn't an AJAX request, return a 404
77
        if (! request()->ajax()) {
78
            abort(404);
79
        }
80
81
        return view(
82
            $this->crud->getFirstFieldView('form.create_form'),
83
            [
84
                'fields'             => $this->crud->getCreateFields(),
85
                'action'             => 'create',
86
                'crud'               => $this->crud,
87
                'modalClass'         => request()->get('modal_class'),
88
                'parentLoadedAssets' => request()->get('parent_loaded_assets'),
89
            ]
90
        );
91
92
    }        
93
       
94
95
96
    /**
97
     * Store a newly created resource in the database.
98
     *
99
     * @return \Illuminate\Http\RedirectResponse
100
     */
101
    public function store()
102
    {
103
        $this->crud->hasAccessOrFail('create');
104
105
        // execute the FormRequest authorization and validation, if one is required
106
        $request = $this->crud->validateRequest();
107
108
        // register any Model Events defined on fields
109
        $this->crud->registerFieldEvents();
110
111
        // insert item in the db
112
        $item = $this->crud->create($this->crud->getStrippedSaveRequest($request));
113
        $this->data['entry'] = $this->crud->entry = $item;
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
114
115
        // show a success message
116
        \Alert::success(trans('backpack::crud.insert_success'))->flash();
0 ignored issues
show
Bug introduced by
The type Alert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
117
118
        // save the redirect choice for next time
119
        $this->crud->setSaveAction();
120
121
        return $this->crud->performSaveAction($item->getKey());
122
    }
123
}
124