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

CreateOperation::createForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 17
rs 9.9332
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
32
    /**
33
     * Add the default settings, buttons, etc that this operation needs.
34
     */
35
    protected function setupCreateDefaults()
36
    {
37
        $this->crud->allowAccess('create');
38
39
        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

39
        LifecycleHook::/** @scrutinizer ignore-call */ 
40
                       hookInto('create:before_setup', function () {
Loading history...
40
            $this->crud->setupDefaultSaveActions();
41
        });
42
43
        LifecycleHook::hookInto('list:before_setup', function () {
44
            $this->crud->addButton('top', 'create', 'view', 'crud::buttons.create');
45
        });
46
    }
47
48
    /**
49
     * Show the form for creating inserting a new row.
50
     *
51
     * @return \Illuminate\Contracts\View\View
52
     */
53
    public function create()
54
    {
55
        $this->crud->hasAccessOrFail('create');
56
57
        // prepare the fields you need to show
58
        $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...
59
        $this->data['saveAction'] = $this->crud->getSaveAction();
60
        $this->data['title'] = $this->crud->getTitle() ?? trans('backpack::crud.add').' '.$this->crud->entity_name;
61
62
        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
63
        return  request()->ajax() ? 
64
            view('crud::components.form.form_ajax_view', $this->data) :
65
            view($this->crud->getCreateView(), $this->data);
66
    }
67
68
    public function createForm()
69
    {
70
        $this->crud->hasAccessOrFail('create');
71
72
        // if the request isn't an AJAX request, return a 404
73
        if (! request()->ajax()) {
74
            abort(404);
75
        }
76
77
        return view(
78
            $this->crud->getFirstFieldView('form.create_form'),
79
            [
80
                'fields' => $this->crud->getCreateFields(),
81
                'action' => 'create',
82
                'crud' => $this->crud,
83
                'modalClass' => request()->get('modal_class'),
84
                'parentLoadedAssets' => request()->get('parent_loaded_assets'),
85
            ]
86
        );
87
    }
88
89
    /**
90
     * Store a newly created resource in the database.
91
     *
92
     * @return \Illuminate\Http\RedirectResponse
93
     */
94
    public function store()
95
    {
96
        $this->crud->hasAccessOrFail('create');
97
98
        // execute the FormRequest authorization and validation, if one is required
99
        $request = $this->crud->validateRequest();
100
101
        // register any Model Events defined on fields
102
        $this->crud->registerFieldEvents();
103
104
        // insert item in the db
105
        $item = $this->crud->create($this->crud->getStrippedSaveRequest($request));
106
        $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...
107
108
        // show a success message
109
        \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...
110
111
        // save the redirect choice for next time
112
        $this->crud->setSaveAction();
113
114
        return $this->crud->performSaveAction($item->getKey());
115
    }
116
}
117