We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
6 | trait SaveActions |
||
7 | { |
||
8 | /** |
||
9 | * Get the save configured save action or the one stored in a session variable. |
||
10 | * @return [type] [description] |
||
|
|||
11 | */ |
||
12 | public function getSaveAction() |
||
13 | { |
||
14 | $cantCreate = ! $this->crud->hasAccess('create'); |
||
15 | $saveAction = session('save_action', config('backpack.crud.default_save_action', 'save_and_back')); |
||
16 | if ($saveAction == 'save_and_new' && $cantCreate) { |
||
17 | $saveAction = 'save_and_back'; |
||
18 | } |
||
19 | $saveOptions = []; |
||
20 | $saveCurrent = [ |
||
21 | 'value' => $saveAction, |
||
22 | 'label' => $this->getSaveActionButtonName($saveAction), |
||
23 | ]; |
||
24 | |||
25 | switch ($saveAction) { |
||
26 | case 'save_and_edit': |
||
27 | $saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back'); |
||
28 | $saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new'); |
||
29 | break; |
||
30 | View Code Duplication | case 'save_and_new': |
|
31 | $saveOptions['save_and_back'] = $this->getSaveActionButtonName('save_and_back'); |
||
32 | $saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit'); |
||
33 | break; |
||
34 | case 'save_and_back': |
||
35 | View Code Duplication | default: |
|
36 | $saveOptions['save_and_edit'] = $this->getSaveActionButtonName('save_and_edit'); |
||
37 | $saveOptions['save_and_new'] = $this->getSaveActionButtonName('save_and_new'); |
||
38 | break; |
||
39 | } |
||
40 | |||
41 | if ($cantCreate) { |
||
42 | unset($saveOptions['save_and_new']); |
||
43 | } |
||
44 | |||
45 | return [ |
||
46 | 'active' => $saveCurrent, |
||
47 | 'options' => $saveOptions, |
||
48 | ]; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Change the session variable that remembers what to do after the "Save" action. |
||
53 | * @param [type] $forceSaveAction [description] |
||
54 | */ |
||
55 | public function setSaveAction($forceSaveAction = null) |
||
56 | { |
||
57 | if ($forceSaveAction) { |
||
58 | $saveAction = $forceSaveAction; |
||
59 | } else { |
||
60 | $saveAction = \Request::input('save_action', config('backpack.crud.default_save_action', 'save_and_back')); |
||
61 | } |
||
62 | |||
63 | if (session('save_action', 'save_and_back') !== $saveAction && config('backpack.crud.show_save_action_change', true)) { |
||
64 | \Alert::info(trans('backpack::crud.save_action_changed_notification'))->flash(); |
||
65 | } |
||
66 | |||
67 | session(['save_action' => $saveAction]); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Redirect to the correct URL, depending on which save action has been selected. |
||
72 | * @param [type] $itemId [description] |
||
73 | * @return [type] [description] |
||
74 | */ |
||
75 | public function performSaveAction($itemId = null) |
||
76 | { |
||
77 | $saveAction = \Request::input('save_action', config('backpack.crud.default_save_action', 'save_and_back')); |
||
78 | $itemId = $itemId ? $itemId : \Request::input('id'); |
||
79 | |||
80 | switch ($saveAction) { |
||
81 | case 'save_and_new': |
||
82 | $redirectUrl = $this->crud->route.'/create'; |
||
83 | break; |
||
84 | case 'save_and_edit': |
||
85 | $redirectUrl = $this->crud->route.'/'.$itemId.'/edit'; |
||
86 | if (\Request::has('locale')) { |
||
87 | $redirectUrl .= '?locale='.\Request::input('locale'); |
||
88 | } |
||
89 | break; |
||
90 | case 'save_and_back': |
||
91 | default: |
||
92 | $redirectUrl = $this->crud->route; |
||
93 | break; |
||
94 | } |
||
95 | |||
96 | return \Redirect::to($redirectUrl); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get the translated text for the Save button. |
||
101 | * @param string $actionValue [description] |
||
102 | * @return [type] [description] |
||
103 | */ |
||
104 | private function getSaveActionButtonName($actionValue = 'save_and_back') |
||
119 | } |
||
120 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.