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

Test Setup Failed
Pull Request — master (#3214)
by Agus
40:23
created

InlineCreateOperation::setupInlineCreateDefaults()   A

Complexity

Conditions 6
Paths 12

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
c 2
b 0
f 0
nc 12
nop 0
dl 0
loc 18
rs 9.2222
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;
0 ignored issues
show
Unused Code introduced by
The assignment to $inlineFound is dead and can be removed.
Loading history...
38
        foreach (class_uses(self::class) as $key => $value) {
39
            $inlineFound = strpos($value, "\InlineCreateOperation") !== false;
40
            if ($inlineFound && strpos($value, "\CreateOperation") !== false) {
41
                abort(500, 'Inline Create Operation trait should be loaded AFTER Create Operation.');
42
            }
43
        }
44
45
        if (method_exists($this, 'setup')) {
46
            $this->setup();
47
        }
48
        if (method_exists($this, 'setupCreateOperation')) {
49
            $this->setupCreateOperation();
50
        }
51
52
        $this->crud->applyConfigurationFromSettings('create');
53
    }
54
55
    /**
56
     * Returns the HTML of the create form. It's used by the CreateInline operation, to show that form
57
     * inside a popup (aka modal).
58
     */
59
    public function getInlineCreateModal()
60
    {
61
        if (! request()->has('entity')) {
62
            abort(400, 'No "entity" inside the request.');
63
        }
64
65
        return view(
66
            'crud::fields.relationship.inline_create_modal',
67
            [
68
                'fields' => $this->crud->getCreateFields(),
69
                'action' => 'create',
70
                'crud' => $this->crud,
71
                'entity' => request()->get('entity'),
72
                'modalClass' => request()->get('modal_class'),
73
                'parentLoadedFields' => request()->get('parent_loaded_fields'),
74
            ]
75
        );
76
    }
77
78
    /**
79
     * Runs the store() function in controller like a regular crud create form.
80
     * Developer might overwrite this if he wants some custom save behaviour when added on the fly.
81
     *
82
     * @return void
83
     */
84
    public function storeInlineCreate()
85
    {
86
        $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

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