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 | |||
| 27 | /** |
||
| 28 | * @var CrudPanel |
||
| 29 | */ |
||
| 30 | public $crud; |
||
| 31 | |||
| 32 | public $request; |
||
| 33 | |||
| 34 | public function __construct() |
||
| 35 | { |
||
| 36 | if (! $this->crud) { |
||
| 37 | $this->crud = app()->make(CrudPanel::class); |
||
| 38 | $this->crud->ajax_table=false; |
||
| 39 | |||
| 40 | // call the setup function inside this closure to also have the request there |
||
| 41 | // this way, developers can use things stored in session (auth variables, etc) |
||
| 42 | $this->middleware(function ($request, $next) { |
||
| 43 | $this->request = $request; |
||
| 44 | $this->crud->request = $request; |
||
| 45 | $this->setup(); |
||
| 46 | |||
| 47 | return $next($request); |
||
| 48 | }); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Allow developers to set their configuration options for a CrudPanel. |
||
| 54 | */ |
||
| 55 | public function setup() |
||
| 56 | { |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Display all rows in the database for this entity. |
||
| 61 | * |
||
| 62 | * @return Response |
||
|
|
|||
| 63 | */ |
||
| 64 | public function index() |
||
| 65 | { |
||
| 66 | $this->crud->hasAccessOrFail('list'); |
||
| 67 | |||
| 68 | $this->data['crud'] = $this->crud; |
||
| 69 | $this->data['title'] = ucfirst($this->crud->entity_name_plural); |
||
| 70 | |||
| 71 | // get all entries if AJAX is not enabled |
||
| 72 | if (! $this->data['crud']->ajaxTable()) { |
||
| 73 | $this->data['entries'] = $this->data['crud']->getEntries(); |
||
| 74 | } |
||
| 75 | |||
| 76 | // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package |
||
| 77 | return view($this->crud->getListView(), $this->data); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Show the form for creating inserting a new row. |
||
| 82 | * |
||
| 83 | * @return Response |
||
| 84 | */ |
||
| 85 | public function create() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Store a newly created resource in the database. |
||
| 101 | * |
||
| 102 | * @param StoreRequest $request - type injection used for validation using Requests |
||
| 103 | * |
||
| 104 | * @return \Illuminate\Http\RedirectResponse |
||
| 105 | */ |
||
| 106 | public function storeCrud(StoreRequest $request = null) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Show the form for editing the specified resource. |
||
| 138 | * |
||
| 139 | * @param int $id |
||
| 140 | * |
||
| 141 | * @return Response |
||
| 142 | */ |
||
| 143 | public function edit($id) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Update the specified resource in the database. |
||
| 182 | * |
||
| 183 | * @param UpdateRequest $request - type injection used for validation using Requests |
||
| 184 | * |
||
| 185 | * @return \Illuminate\Http\RedirectResponse |
||
| 186 | */ |
||
| 187 | public function updateCrud(UpdateRequest $request = null) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Display the specified resource. |
||
| 219 | * |
||
| 220 | * @param int $id |
||
| 221 | * |
||
| 222 | * @return Response |
||
| 223 | */ |
||
| 224 | public function show($id) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Remove the specified resource from storage. |
||
| 257 | * |
||
| 258 | * @param int $id |
||
| 259 | * |
||
| 260 | * @return string |
||
| 261 | */ |
||
| 262 | public function destroy($id) |
||
| 271 | |||
| 272 | public function handleEagerLoad($item) |
||
| 293 | } |
||
| 294 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.