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 |
||
10 | class UniquePageCrudController extends CrudController |
||
11 | { |
||
12 | use SaveActions; |
||
13 | use UniquePages; |
||
14 | use TraitReflections; |
||
15 | |||
16 | public function setup() |
||
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 | public function update($slug, $id) |
||
74 | |||
75 | /** |
||
76 | * Set the crud route. |
||
77 | * |
||
78 | * @param $slug |
||
79 | */ |
||
80 | public function setRoute($slug) |
||
84 | |||
85 | /** |
||
86 | * Populate the update form with basic fields that all pages need. |
||
87 | * |
||
88 | * @param Model $page |
||
89 | */ |
||
90 | public function addDefaultPageFields($page) |
||
116 | |||
117 | /** |
||
118 | * Build the buttons html for the edit form. |
||
119 | * |
||
120 | * @param Model $page |
||
121 | * @return string |
||
122 | */ |
||
123 | public function buttons($page) |
||
130 | |||
131 | /** |
||
132 | * Create the page by slug. |
||
133 | * |
||
134 | * @param $slug |
||
135 | * @return mixed |
||
136 | */ |
||
137 | public function createMissingPage($slug) |
||
155 | |||
156 | public function listRevisions() |
||
160 | |||
161 | /** |
||
162 | * Display the revisions for specified resource. |
||
163 | * |
||
164 | * @param $slug |
||
165 | * @param $id |
||
166 | * @return Response |
||
167 | */ |
||
168 | View Code Duplication | public function uniqueRevisions($slug, $id) |
|
177 | |||
178 | /** |
||
179 | * Restore a specific revision for the specified resource. |
||
180 | * |
||
181 | * Used via AJAX in the revisions view |
||
182 | * |
||
183 | * @param string $slug |
||
184 | * @param int $id |
||
185 | * |
||
186 | * @return JSON Response containing the new revision that was created from the update |
||
187 | * @return HTTP 500 if the request did not contain the revision ID |
||
188 | */ |
||
189 | View Code Duplication | public function restoreUniqueRevision($slug, $id) |
|
198 | |||
199 | /** |
||
200 | * Setup the controller for the entry. |
||
201 | * |
||
202 | * @param $entry |
||
203 | */ |
||
204 | protected function uniqueSetup($entry) |
||
213 | |||
214 | /* |
||
215 | |-------------------------------------------------------------------------- |
||
216 | | SaveActions overrides |
||
217 | |-------------------------------------------------------------------------- |
||
218 | */ |
||
219 | |||
220 | /** |
||
221 | * Overrides trait version to remove 'save_and_back' and 'save_and_new'. |
||
222 | * |
||
223 | * @return [type] [description] |
||
224 | */ |
||
225 | public function getSaveAction() |
||
237 | |||
238 | /** |
||
239 | * Override trait version to not update the session variable |
||
240 | * |
||
241 | * @param [type] $forceSaveAction [description] |
||
242 | */ |
||
243 | public function setSaveAction($forceSaveAction = null) |
||
247 | } |
||
248 |
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 theSon
calls the wrong method in the parent class.