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 |
||
| 25 | class JqadmController extends AdminController |
||
| 26 | { |
||
| 27 | use AuthorizesRequests; |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Returns the JS file content |
||
| 32 | * |
||
| 33 | * @return \Illuminate\Http\Response Response object containing the generated output |
||
| 34 | */ |
||
| 35 | public function fileAction() |
||
| 36 | { |
||
| 37 | if( config( 'shop.authorize', true ) ) { |
||
| 38 | $this->authorize( 'admin', [JqadmController::class, ['admin', 'editor', 'super']] ); |
||
| 39 | } |
||
| 40 | |||
| 41 | $contents = ''; |
||
| 42 | $files = array(); |
||
| 43 | $aimeos = app( '\Aimeos\Shop\Base\Aimeos' )->get(); |
||
| 44 | $type = Route::input( 'type', Input::get( 'type', 'js' ) ); |
||
| 45 | |||
| 46 | foreach( $aimeos->getCustomPaths( 'admin/jqadm' ) as $base => $paths ) |
||
| 47 | { |
||
| 48 | foreach( $paths as $path ) |
||
| 49 | { |
||
| 50 | $jsbAbsPath = $base . '/' . $path; |
||
| 51 | $jsb2 = new \Aimeos\MW\Jsb2\Standard( $jsbAbsPath, dirname( $jsbAbsPath ) ); |
||
| 52 | $files = array_merge( $files, $jsb2->getFiles( $type ) ); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | foreach( $files as $file ) |
||
| 57 | { |
||
| 58 | if( ( $content = file_get_contents( $file ) ) !== false ) { |
||
| 59 | $contents .= $content; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | $response = response( $contents ); |
||
| 64 | |||
| 65 | if( $type === 'js' ) { |
||
| 66 | $response->header( 'Content-Type', 'application/javascript' ); |
||
|
|
|||
| 67 | } elseif( $type === 'css' ) { |
||
| 68 | $response->header( 'Content-Type', 'text/css' ); |
||
| 69 | } |
||
| 70 | |||
| 71 | return $response; |
||
| 72 | } |
||
| 73 | |||
| 74 | |||
| 75 | /** |
||
| 76 | * Returns the HTML code for a copy of a resource object |
||
| 77 | * |
||
| 78 | * @return string Generated output |
||
| 79 | */ |
||
| 80 | View Code Duplication | public function copyAction() |
|
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * Returns the HTML code for a new resource object |
||
| 98 | * |
||
| 99 | * @return string Generated output |
||
| 100 | */ |
||
| 101 | View Code Duplication | public function createAction() |
|
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * Deletes the resource object or a list of resource objects |
||
| 119 | * |
||
| 120 | * @return string Generated output |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function deleteAction() |
|
| 136 | |||
| 137 | |||
| 138 | /** |
||
| 139 | * Exports the data for a resource object |
||
| 140 | * |
||
| 141 | * @return string Generated output |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function exportAction() |
|
| 157 | |||
| 158 | |||
| 159 | /** |
||
| 160 | * Returns the HTML code for the requested resource object |
||
| 161 | * |
||
| 162 | * @return string Generated output |
||
| 163 | */ |
||
| 164 | View Code Duplication | public function getAction() |
|
| 178 | |||
| 179 | |||
| 180 | /** |
||
| 181 | * Saves a new resource object |
||
| 182 | * |
||
| 183 | * @return string Generated output |
||
| 184 | */ |
||
| 185 | View Code Duplication | public function saveAction() |
|
| 199 | |||
| 200 | |||
| 201 | /** |
||
| 202 | * Returns the HTML code for a list of resource objects |
||
| 203 | * |
||
| 204 | * @return string Generated output |
||
| 205 | */ |
||
| 206 | View Code Duplication | public function searchAction() |
|
| 220 | |||
| 221 | |||
| 222 | /** |
||
| 223 | * Returns the resource controller |
||
| 224 | * |
||
| 225 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||
| 226 | */ |
||
| 227 | protected function createClient() |
||
| 243 | |||
| 244 | |||
| 245 | /** |
||
| 246 | * Returns the generated HTML code |
||
| 247 | * |
||
| 248 | * @param string $content Content from admin client |
||
| 249 | * @return \Illuminate\Contracts\View\View View for rendering the output |
||
| 250 | */ |
||
| 251 | protected function getHtml( $content ) |
||
| 262 | } |
||
| 263 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.