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 Cristian
14:46
created

setupDefaultInlineCreateOperation()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 13
rs 10
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' => 'DefaultInlineCreate',
23
        ]);
24
        Route::post($segment.'/inline/create', [
25
            'as'        => $segment.'-inline-create-save',
26
            'uses'      => $controller.'@storeInlineCreate',
27
            'operation' => 'DefaultInlineCreate',
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
     *  We use this setup to make this operation behaviour similar to other operations, so developer could still override
37
     *  the defaults with `setupInlineCreateOperation` as with any other operation.
38
     *
39
     *  `setupInlineCreateDefaults` is not used because of the time it is called in the stack. The "defaults" are applied in backpack
40
     *  to all operations, before applying operation specific setups. As this operation directly need to call other
41
     *  methods in the CrudController, it should only be "initialized" when it's requested.
42
     *
43
     *  To solve the mentioned problems we initialize the operation defaults at the same time we apply developer setup. Developer settings
44
     *  are applied after the defaults to prevail.
45
     */
46
    protected function setupDefaultInlineCreateOperation()
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
        if (method_exists($this, 'setupInlineCreateOperation')) {
58
            $this->setupInlineCreateOperation();
59
        }
60
    }
61
62
    /**
63
     * Returns the HTML of the create form. It's used by the CreateInline operation, to show that form
64
     * inside a popup (aka modal).
65
     */
66
    public function getInlineCreateModal()
67
    {
68
        if (! request()->has('entity')) {
69
            abort(400, 'No "entity" inside the request.');
70
        }
71
72
        return view(
73
            'crud::fields.relationship.inline_create_modal',
74
            [
75
                'fields' => $this->crud->getCreateFields(),
76
                'action' => 'create',
77
                'crud' => $this->crud,
78
                'entity' => request()->get('entity'),
79
                'modalClass' => request()->get('modal_class'),
80
                'parentLoadedFields' => request()->get('parent_loaded_fields'),
81
            ]
82
        );
83
    }
84
85
    /**
86
     * Runs the store() function in controller like a regular crud create form.
87
     * Developer might overwrite this if he wants some custom save behaviour when added on the fly.
88
     *
89
     * @return void
90
     */
91
    public function storeInlineCreate()
92
    {
93
        $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

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