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 (#3214)
by Agus
18:54
created

InlineCreateOperation::setupInlineCreateDefaults()   B

Complexity

Conditions 7
Paths 20

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 11
c 1
b 0
f 0
nc 20
nop 0
dl 0
loc 20
rs 8.8333
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
     * Setup operation default settings. We run setup() and setupCreateOperation() because those are run in middleware
33
     * and to get the fields we need them earlier in application lifecycle.
34
     */
35
    protected function setupInlineCreateDefaults()
36
    {
37
        $inlineFound = false;
38
        foreach (class_uses(self::class) as $key => $value) {
39
            if (strpos($value, "\InlineCreateOperation") !== false) {
40
                $inlineFound = true;
41
            }
42
            if ($inlineFound && strpos($value, "\CreateOperation") !== false) {
43
                abort(500, 'Inline Create Operation trait should be loaded AFTER Create Operation.');
44
            }
45
        }
46
47
        if (method_exists($this, 'setup')) {
48
            $this->setup();
49
        }
50
        if (method_exists($this, 'setupCreateOperation')) {
51
            $this->setupCreateOperation();
52
        }
53
54
        $this->crud->applyConfigurationFromSettings('create');
55
    }
56
57
    /**
58
     * Returns the HTML of the create form. It's used by the CreateInline operation, to show that form
59
     * inside a popup (aka modal).
60
     */
61
    public function getInlineCreateModal()
62
    {
63
        if (! request()->has('entity')) {
64
            abort(400, 'No "entity" inside the request.');
65
        }
66
67
        return view(
68
            'crud::fields.relationship.inline_create_modal',
69
            [
70
                'fields' => $this->crud->getCreateFields(),
71
                'action' => 'create',
72
                'crud' => $this->crud,
73
                'entity' => request()->get('entity'),
74
                'modalClass' => request()->get('modal_class'),
75
                'parentLoadedFields' => request()->get('parent_loaded_fields'),
76
            ]
77
        );
78
    }
79
80
    /**
81
     * Runs the store() function in controller like a regular crud create form.
82
     * Developer might overwrite this if he wants some custom save behaviour when added on the fly.
83
     *
84
     * @return void
85
     */
86
    public function storeInlineCreate()
87
    {
88
        $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

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