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 |
||
| 23 | class JqadmController extends Controller |
||
| 24 | { |
||
| 25 | use AuthorizesRequests; |
||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * Returns the HTML code for a copy of a resource object |
||
| 30 | * |
||
| 31 | * @param string Resource location, e.g. "product" |
||
| 32 | * @param string $sitecode Unique site code |
||
|
|
|||
| 33 | * @param integer $id Unique resource ID |
||
| 34 | * @return string Generated output |
||
| 35 | */ |
||
| 36 | public function copyAction( $site = 'default', $resource, $id ) |
||
| 47 | |||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns the HTML code for a new resource object |
||
| 51 | * |
||
| 52 | * @param string Resource location, e.g. "product" |
||
| 53 | * @param string $sitecode Unique site code |
||
| 54 | * @return string Generated output |
||
| 55 | */ |
||
| 56 | public function createAction( $site = 'default', $resource ) |
||
| 67 | |||
| 68 | |||
| 69 | /** |
||
| 70 | * Deletes the resource object or a list of resource objects |
||
| 71 | * |
||
| 72 | * @param string Resource location, e.g. "product" |
||
| 73 | * @param string $sitecode Unique site code |
||
| 74 | * @param integer $id Unique resource ID |
||
| 75 | * @return string Generated output |
||
| 76 | */ |
||
| 77 | View Code Duplication | public function deleteAction( $site = 'default', $resource, $id ) |
|
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * Returns the HTML code for the requested resource object |
||
| 92 | * |
||
| 93 | * @param string Resource location, e.g. "product" |
||
| 94 | * @param string $sitecode Unique site code |
||
| 95 | * @param integer $id Unique resource ID |
||
| 96 | * @return string Generated output |
||
| 97 | */ |
||
| 98 | public function getAction( $site = 'default', $resource, $id ) |
||
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * Saves a new resource object |
||
| 113 | * |
||
| 114 | * @param string Resource location, e.g. "product" |
||
| 115 | * @param string $sitecode Unique site code |
||
| 116 | * @return string Generated output |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function saveAction( $site = 'default', $resource ) |
|
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * Returns the HTML code for a list of resource objects |
||
| 133 | * |
||
| 134 | * @param string Resource location, e.g. "product" |
||
| 135 | * @param string $sitecode Unique site code |
||
| 136 | * @return string Generated output |
||
| 137 | */ |
||
| 138 | public function searchAction( $site = 'default', $resource ) |
||
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns the resource controller |
||
| 153 | * |
||
| 154 | * @param string $sitecode Unique site code |
||
| 155 | * @return \Aimeos\MShop\Context\Item\Iface Context item |
||
| 156 | */ |
||
| 157 | View Code Duplication | protected function createClient( $sitecode, $resource ) |
|
| 172 | |||
| 173 | |||
| 174 | /** |
||
| 175 | * Sets the locale item in the given context |
||
| 176 | * |
||
| 177 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
| 178 | * @param string $sitecode Unique site code |
||
| 179 | * @param string $lang ISO language code, e.g. "en" or "en_GB" |
||
| 180 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
| 181 | */ |
||
| 182 | View Code Duplication | protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $sitecode, $lang ) |
|
| 202 | } |
||
| 203 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.