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

Completed
Pull Request — master (#145)
by Owen
04:29 queued 01:26
created

SaveActions::performSaveAction()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
nc 8
nop 1
dl 0
loc 20
rs 8.8571
c 1
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures;
4
5
//save_and_back save_and_edit save_and_new
6
trait SaveActions
7
{
8
    public function getSaveAction()
9
    {
10
        $saveAction = session('save_action', config('backback.crud.default_save_action', 'save_and_back'));
11
        $saveOptions = [];
12
        $saveCurrent = [
13
            'value' => $saveAction,
14
            'label' => $this->getSaveActionButtonName($saveAction),
15
        ];
16
17
        switch ($saveAction) {
18 View Code Duplication
            case 'save_and_edit':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
                $saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back');
20
                $saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new');
21
                break;
22 View Code Duplication
            case 'save_and_new':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
                $saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back');
24
                $saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit');
25
                break;
26
            case 'save_and_black':
27 View Code Duplication
            default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
                $saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit');
29
                $saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new');
30
                break;
31
        }
32
33
        return [
34
            'active' => $saveCurrent,
35
            'options' => $saveOptions,
36
        ];
37
    }
38
39
    public function setSaveAction($forceSaveAction = null)
40
    {
41
        if ($forceSaveAction) {
42
            $saveAction = $forceSaveAction;
43
        } else {
44
            $saveAction = \Request::input('save_action', config('backback.crud.default_save_action', 'save_and_back'));
45
        }
46
47
        if (session('save_action', 'save_and_back') !== $saveAction) {
48
            \Alert::info(trans('backpack::crud.save_action_changed_notification'))->flash();
49
        }
50
51
        session(['save_action' => $saveAction]);
52
    }
53
54
    public function performSaveAction($itemId = null)
55
    {
56
        $saveAction = \Request::input('save_action', config('backback.crud.default_save_action', 'save_and_back'));
57
        $itemId = $itemId ? $itemId : \Request::input('id');
58
59
        switch ($saveAction) {
60
            case 'save_and_new':
61
                $redirectUrl = $this->crud->route.'/create';
0 ignored issues
show
Bug introduced by
The property crud does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
62
                break;
63
            case 'save_and_edit':
64
                $redirectUrl = $this->crud->route.'/'.$itemId.'/edit';
65
                break;
66
            case 'save_and_back':
67
            default:
68
                $redirectUrl = $this->crud->route;
69
                break;
70
        }
71
72
        return \Redirect::to($redirectUrl);
73
    }
74
75
    private function getSaveActionButtonName($actionValue = 'save_and_black')
76
    {
77
        switch ($actionValue) {
78
            case 'save_and_edit':
79
                return trans('backpack::crud.save_action_save_and_edit');
80
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
81
            case 'save_and_new':
82
                return trans('backpack::crud.save_action_save_and_new');
83
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
84
            case 'save_and_back':
85
            default:
86
                return trans('backpack::crud.save_action_save_and_back');
87
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
88
        }
89
    }
90
}
91