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 |
||
20 | class CrudController extends BaseController |
||
21 | { |
||
22 | use DispatchesJobs, ValidatesRequests; |
||
23 | use AjaxTable, Reorder, Revisions, ShowDetailsRow, SaveActions; |
||
24 | |||
25 | public $data = []; |
||
26 | public $crud; |
||
27 | public $request; |
||
28 | |||
29 | public function __construct() |
||
45 | |||
46 | /** |
||
47 | * Allow developers to set their configuration options for a CrudPanel. |
||
48 | */ |
||
49 | public function setup() |
||
52 | |||
53 | /** |
||
54 | * Display all rows in the database for this entity. |
||
55 | * |
||
56 | * @return Response |
||
|
|||
57 | */ |
||
58 | public function index() |
||
59 | { |
||
60 | $this->crud->hasAccessOrFail('list'); |
||
61 | |||
62 | $this->data['crud'] = $this->crud; |
||
63 | $this->data['title'] = ucfirst($this->crud->entity_name_plural); |
||
64 | |||
65 | // get all entries if AJAX is not enabled |
||
66 | if (! $this->data['crud']->ajaxTable()) { |
||
67 | $this->data['entries'] = $this->data['crud']->getEntries(); |
||
68 | } |
||
69 | |||
70 | // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
||
71 | return view($this->crud->getListView(), $this->data); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Show the form for creating inserting a new row. |
||
76 | * |
||
77 | * @return Response |
||
78 | */ |
||
79 | public function create() |
||
80 | { |
||
81 | $this->crud->hasAccessOrFail('create'); |
||
82 | |||
83 | // prepare the fields you need to show |
||
84 | $this->data['crud'] = $this->crud; |
||
85 | $this->data['saveAction'] = $this->getSaveAction(); |
||
86 | $this->data['fields'] = $this->crud->getCreateFields(); |
||
87 | $this->data['title'] = trans('backpack::crud.add').' '.$this->crud->entity_name; |
||
88 | |||
89 | // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
||
90 | return view($this->crud->getCreateView(), $this->data); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Store a newly created resource in the database. |
||
95 | * |
||
96 | * @param StoreRequest $request - type injection used for validation using Requests |
||
97 | * |
||
98 | * @return \Illuminate\Http\RedirectResponse |
||
99 | */ |
||
100 | public function storeCrud(StoreRequest $request = null) |
||
101 | { |
||
102 | $this->crud->hasAccessOrFail('create'); |
||
103 | |||
104 | // fallback to global request instance |
||
105 | if (is_null($request)) { |
||
106 | $request = \Request::instance(); |
||
107 | } |
||
108 | |||
109 | // replace empty values with NULL, so that it will work with MySQL strict mode on |
||
110 | View Code Duplication | foreach ($request->input() as $key => $value) { |
|
111 | if (empty($value) && $value !== '0') { |
||
112 | $request->request->set($key, null); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | // insert item in the db |
||
117 | $item = $this->crud->create($request->except(['save_action', '_token', '_method'])); |
||
118 | $this->data['entry'] = $this->crud->entry = $item; |
||
119 | |||
120 | // show a success message |
||
121 | \Alert::success(trans('backpack::crud.insert_success'))->flash(); |
||
122 | |||
123 | // save the redirect choice for next time |
||
124 | $this->setSaveAction(); |
||
125 | |||
126 | return $this->performSaveAction($item->getKey()); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Show the form for editing the specified resource. |
||
131 | * |
||
132 | * @param int $id |
||
133 | * |
||
134 | * @return Response |
||
135 | */ |
||
136 | public function edit($id) |
||
152 | |||
153 | /** |
||
154 | * Update the specified resource in the database. |
||
155 | * |
||
156 | * @param UpdateRequest $request - type injection used for validation using Requests |
||
157 | * |
||
158 | * @return \Illuminate\Http\RedirectResponse |
||
159 | */ |
||
160 | public function updateCrud(UpdateRequest $request = null) |
||
189 | |||
190 | /** |
||
191 | * Display the specified resource. |
||
192 | * |
||
193 | * @param int $id |
||
194 | * |
||
195 | * @return Response |
||
196 | */ |
||
197 | public function show($id) |
||
224 | |||
225 | /** |
||
226 | * Remove the specified resource from storage. |
||
227 | * |
||
228 | * @param int $id |
||
229 | * |
||
230 | * @return string |
||
231 | */ |
||
232 | public function destroy($id) |
||
238 | } |
||
239 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.