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
Pull Request — master (#3521)
by
unknown
10:35
created

InlineCreateOperation::setupInlineCreateDefaults()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
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 Illuminate\Support\Facades\Route;
6
use Prologue\Alerts\Facades\Alert;
7
8
trait InlineCreateOperation
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 setupInlineCreateRoutes($segment, $routeName, $controller)
0 ignored issues
show
Unused Code introduced by
The parameter $routeName is not used and could be removed. ( Ignorable by Annotation )

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

17
    protected function setupInlineCreateRoutes($segment, /** @scrutinizer ignore-unused */ $routeName, $controller)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        Route::post($segment.'/inline/create/modal', [
20
            'as'        => $segment.'-inline-create',
21
            'uses'      => $controller.'@getInlineCreateModal',
22
            'operation' => 'InlineCreate',
23
        ]);
24
        Route::post($segment.'/inline/create', [
25
            'as'        => $segment.'-inline-create-save',
26
            'uses'      => $controller.'@storeInlineCreate',
27
            'operation' => 'InlineCreate',
28
        ]);
29
    }
30
31
    /**
32
     *  This operation have some known quirks that can only be addressed using this setup instead of `setupInlineCreateDefaults`
33
     *  1 - InlineCreateOperation must be added AFTER CreateOperation trait.
34
     *  2 - setup() in controllers that have the InlineCreateOperations need to be called twice (technically we are re-creating a new crud).
35
     *
36
     *  Both problems are solved using this setup because it will only be called when InlineCreate route is requested, so even that we need to call
37
     *  setup again (we are creating a "new" crud panel to show in modal), it will not affect other operation setups.
38
     *
39
     *  The downside of it, and why we need this explanation note, is that using `setupInlineCreateOperation`
40
     *  in your CrudController to override/configure this operation will not have the same behaviour as
41
     *  other operations.
42
     *
43
     *  Usually you would just `setupSomeOperation()` and add your own setup of the operation. In this specific case is a little bit different,
44
     *  this code is the minimum needed to run the operation, and should be present if you override this method in your CrudController.
45
     */
46
    public function setupInlineCreateOperation()
47
    {
48
        if (method_exists($this, 'setup')) {
49
            $this->setup();
50
        }
51
        if (method_exists($this, 'setupCreateOperation')) {
52
            $this->setupCreateOperation();
53
        }
54
55
        $this->crud->applyConfigurationFromSettings('create');
56
    }
57
58
    /**
59
     * Returns the HTML of the create form. It's used by the CreateInline operation, to show that form
60
     * inside a popup (aka modal).
61
     */
62
    public function getInlineCreateModal()
63
    {
64
        if (! request()->has('entity')) {
65
            abort(400, 'No "entity" inside the request.');
66
        }
67
68
        return view(
69
            'crud::fields.relationship.inline_create_modal',
70
            [
71
                'fields' => $this->crud->getCreateFields(),
72
                'action' => 'create',
73
                'crud' => $this->crud,
74
                'entity' => request()->get('entity'),
75
                'modalClass' => request()->get('modal_class'),
76
                'parentLoadedFields' => request()->get('parent_loaded_fields'),
77
            ]
78
        );
79
    }
80
81
    /**
82
     * Runs the store() function in controller like a regular crud create form.
83
     * Developer might overwrite this if he wants some custom save behaviour when added on the fly.
84
     *
85
     * @return void
86
     */
87
    public function storeInlineCreate()
88
    {
89
        $result = $this->store();
0 ignored issues
show
Bug introduced by
It seems like store() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

89
        /** @scrutinizer ignore-call */ 
90
        $result = $this->store();
Loading history...
90
91
        // do not carry over the flash messages from the Create operation
92
        Alert::flush();
93
94
        return $result;
95
    }
96
}
97