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 |
||
| 21 | class LocaliseTableLocalise extends JTable |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Primary Key |
||
| 25 | * |
||
| 26 | * @var int |
||
| 27 | */ |
||
| 28 | public $id = null; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The title to use for the asset table |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | public $path = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Checked out status |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | public $checked_out = null; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Checkout out time |
||
| 46 | * |
||
| 47 | * @var date |
||
| 48 | */ |
||
| 49 | public $checked_out_time = null; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * The asset ID |
||
| 53 | * |
||
| 54 | * @var asset_id |
||
| 55 | */ |
||
| 56 | public $asset_id = null; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Constructor |
||
| 60 | * |
||
| 61 | * @param object &$db Database connector object |
||
| 62 | */ |
||
| 63 | public function __construct(&$db) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Method to compute the default name of the asset. |
||
| 70 | * The default name is in the form `table_name.id` |
||
| 71 | * where id is the value of the primary key of the table. |
||
| 72 | * |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | protected function _getAssetName() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Method to return the title to use for the asset table. |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | * |
||
| 87 | * @since 1.6 |
||
| 88 | */ |
||
| 89 | protected function _getAssetTitle() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get the parent asset id for the record |
||
| 96 | * |
||
| 97 | * @param JTable $table JTable Table object |
||
| 98 | * @param Integer $id Primart key of table |
||
| 99 | * |
||
| 100 | * @return Integer Parent asset id for the record |
||
| 101 | */ |
||
| 102 | protected function _getAssetParentId(JTable $table = null, $id = null) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Method to delete a row from the database table by primary key value. |
||
| 190 | * |
||
| 191 | * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. |
||
| 192 | * |
||
| 193 | * @return boolean True on success. |
||
| 194 | * |
||
| 195 | * @link http://docs.joomla.org/JTable/delete |
||
| 196 | * @since 11.1 |
||
| 197 | * @throws UnexpectedValueException |
||
| 198 | */ |
||
| 199 | public function delete($pk = null) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Delete language translations |
||
| 211 | * |
||
| 212 | * @return boolean |
||
| 213 | */ |
||
| 214 | protected function deleteLanguageTranslations() |
||
| 249 | } |
||
| 250 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.