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 |
||
| 11 | class UniquePageCrudController extends CrudController |
||
| 12 | { |
||
| 13 | use SaveActions; |
||
| 14 | use UniquePages; |
||
| 15 | use TraitReflections; |
||
| 16 | |||
| 17 | public function setup() |
||
| 18 | { |
||
| 19 | parent::__construct(); |
||
|
|
|||
| 20 | |||
| 21 | $modelClass = config('backpack.pagemanager.unique_page_model_class', 'Backpack\PageManager\app\Models\Page'); |
||
| 22 | |||
| 23 | $this->checkForTemplatesAndUniquePagesNotDistinct(); |
||
| 24 | |||
| 25 | /* |
||
| 26 | |-------------------------------------------------------------------------- |
||
| 27 | | BASIC CRUD INFORMATION |
||
| 28 | |-------------------------------------------------------------------------- |
||
| 29 | */ |
||
| 30 | $this->crud->setModel($modelClass); |
||
| 31 | // Don't set route or entity names here. These depend on the page you are editing |
||
| 32 | |||
| 33 | // unique pages cannot be created nor deleted |
||
| 34 | $this->crud->denyAccess(['list', 'create', 'delete']); |
||
| 35 | |||
| 36 | if (config('backpack.pagemanager.unique_page_revisions')) { |
||
| 37 | $this->crud->allowAccess('revisions'); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Edit the unique page retrieved by slug. |
||
| 43 | * |
||
| 44 | * @param string $slug |
||
| 45 | * @return Response |
||
| 46 | */ |
||
| 47 | public function uniqueEdit($slug) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Update the unique page. |
||
| 63 | * |
||
| 64 | * @param string $slug |
||
| 65 | * @param int $id |
||
| 66 | * @return \Illuminate\Http\RedirectResponse |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function update($slug, $id) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Set the crud route. |
||
| 80 | * |
||
| 81 | * @param $slug |
||
| 82 | */ |
||
| 83 | public function setRoute($slug) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Populate the update form with basic fields that all pages need. |
||
| 90 | * |
||
| 91 | * @param Model $page |
||
| 92 | */ |
||
| 93 | public function addDefaultPageFields($page) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Build the buttons html for the edit form. |
||
| 122 | * |
||
| 123 | * @param Model $page |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | public function buttons($page) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Create the page by slug. |
||
| 136 | * |
||
| 137 | * @param $slug |
||
| 138 | * @return mixed |
||
| 139 | */ |
||
| 140 | public function createMissingPage($slug) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Display the revisions for specified resource. |
||
| 161 | * |
||
| 162 | * @param $slug |
||
| 163 | * @param $id |
||
| 164 | * @return Response |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function uniqueRevisions($slug, $id) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Restore a specific revision for the specified resource. |
||
| 178 | * |
||
| 179 | * Used via AJAX in the revisions view |
||
| 180 | * |
||
| 181 | * @param string $slug |
||
| 182 | * @param int $id |
||
| 183 | * |
||
| 184 | * @return JSON Response containing the new revision that was created from the update |
||
| 185 | * @return HTTP 500 if the request did not contain the revision ID |
||
| 186 | */ |
||
| 187 | View Code Duplication | public function restoreUniqueRevision($slug, $id) |
|
| 196 | |||
| 197 | /** |
||
| 198 | * Setup the controller for the entry. |
||
| 199 | * |
||
| 200 | * @param $entry |
||
| 201 | */ |
||
| 202 | protected function uniqueSetup($entry) |
||
| 211 | |||
| 212 | /* |
||
| 213 | |-------------------------------------------------------------------------- |
||
| 214 | | SaveActions overrides |
||
| 215 | |-------------------------------------------------------------------------- |
||
| 216 | */ |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Overrides trait version to remove 'save_and_back' and 'save_and_new'. |
||
| 220 | * |
||
| 221 | * @return [type] [description] |
||
| 222 | */ |
||
| 223 | public function getSaveAction() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Override trait version to not update the session variable. |
||
| 238 | * |
||
| 239 | * @param [type] $forceSaveAction [description] |
||
| 240 | */ |
||
| 241 | public function setSaveAction($forceSaveAction = null) |
||
| 245 | } |
||
| 246 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.