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) |
||
91 | { |
||
92 | $fields = [ |
||
93 | [ |
||
94 | 'name' => 'buttons', |
||
95 | 'type' => 'custom_html', |
||
96 | 'value' => $this->buttons($page), |
||
97 | ], |
||
98 | [ |
||
99 | 'name' => 'template', |
||
100 | 'type' => 'hidden', |
||
101 | ], |
||
102 | [ |
||
103 | 'name' => 'name', |
||
104 | ], |
||
105 | [ |
||
106 | 'name' => 'title', |
||
107 | ], |
||
108 | [ |
||
109 | 'name' => 'slug', |
||
110 | 'type' => 'hidden', |
||
111 | ], |
||
112 | ]; |
||
113 | |||
114 | $this->crud->addFields($fields); |
||
115 | } |
||
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 | /** |
||
157 | * Display the revisions for specified resource. |
||
158 | * |
||
159 | * @param $slug |
||
160 | * @param $id |
||
161 | * @return Response |
||
162 | */ |
||
163 | View Code Duplication | public function uniqueRevisions($slug, $id) |
|
172 | |||
173 | /** |
||
174 | * Restore a specific revision for the specified resource. |
||
175 | * |
||
176 | * Used via AJAX in the revisions view |
||
177 | * |
||
178 | * @param string $slug |
||
179 | * @param int $id |
||
180 | * |
||
181 | * @return JSON Response containing the new revision that was created from the update |
||
182 | * @return HTTP 500 if the request did not contain the revision ID |
||
183 | */ |
||
184 | View Code Duplication | public function restoreUniqueRevision($slug, $id) |
|
193 | |||
194 | /** |
||
195 | * Setup the controller for the entry. |
||
196 | * |
||
197 | * @param $entry |
||
198 | */ |
||
199 | protected function uniqueSetup($entry) |
||
208 | |||
209 | /* |
||
210 | |-------------------------------------------------------------------------- |
||
211 | | SaveActions overrides |
||
212 | |-------------------------------------------------------------------------- |
||
213 | */ |
||
214 | |||
215 | /** |
||
216 | * Overrides trait version to remove 'save_and_back' and 'save_and_new'. |
||
217 | * |
||
218 | * @return [type] [description] |
||
219 | */ |
||
220 | public function getSaveAction() |
||
232 | |||
233 | /** |
||
234 | * Override trait version to not update the session variable. |
||
235 | * |
||
236 | * @param [type] $forceSaveAction [description] |
||
237 | */ |
||
238 | public function setSaveAction($forceSaveAction = null) |
||
242 | } |
||
243 |
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.