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 |
||
| 13 | class mysqli implements driver_interface |
||
| 14 | { |
||
| 15 | /** @var \phpbb\db\driver\driver_interface */ |
||
| 16 | protected $db; |
||
| 17 | |||
| 18 | /** @var string */ |
||
| 19 | protected $engine; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * mysql constructor. |
||
| 23 | * |
||
| 24 | * @param \phpbb\db\driver\driver_interface $db |
||
| 25 | */ |
||
| 26 | public function __construct(\phpbb\db\driver\driver_interface $db) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * {@inheritdoc} |
||
| 33 | */ |
||
| 34 | public function get_name() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | public function get_type() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | public function get_query($topic_id, $topic_title, $length, $sensitivity) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | public function is_supported() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * {@inheritdoc} |
||
| 85 | */ |
||
| 86 | public function is_index($column = 'topic_title') |
||
| 110 | |||
| 111 | /** |
||
| 112 | * {@inheritdoc} |
||
| 113 | */ |
||
| 114 | public function create_fulltext_index($column = 'topic_title') |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Get the database storage engine name |
||
| 125 | * |
||
| 126 | * @access public |
||
| 127 | * @return string The storage engine name |
||
| 128 | */ |
||
| 129 | public function get_engine() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Set the database storage engine name |
||
| 136 | * |
||
| 137 | * @access public |
||
| 138 | * @return string The storage engine name |
||
| 139 | */ |
||
| 140 | public function set_engine() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Alter the database storage engine |
||
| 164 | * |
||
| 165 | * @access public |
||
| 166 | * @param string $engine The storage engine, i.e.: MYISAM|INNODB |
||
| 167 | * @return void |
||
| 168 | */ |
||
| 169 | public function alter_engine($engine = 'MYISAM') |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Get topics table information |
||
| 178 | * |
||
| 179 | * @access protected |
||
| 180 | * @return mixed Array with the table info, false if the table does not exist |
||
| 181 | */ |
||
| 182 | protected function get_table_info() |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Check if the database is using MySQL |
||
| 193 | * |
||
| 194 | * @access public |
||
| 195 | * @return bool True if is mysql, false otherwise |
||
| 196 | */ |
||
| 197 | protected function is_mysql() |
||
| 201 | } |
||
| 202 |