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 postgres_index extends \phpbb\db\migration\migration |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Do not run this migration if the DB is not PostgreSQL |
||
| 17 | * |
||
| 18 | * @return bool |
||
| 19 | */ |
||
| 20 | public function effectively_installed() |
||
| 21 | { |
||
| 22 | return $this->db->get_sql_layer() !== 'postgres' || $this->config->offsetExists('pst_postgres_ts_name'); |
||
| 23 | } |
||
| 24 | |||
| 25 | public static function depends_on() |
||
| 29 | |||
| 30 | public function update_data() |
||
| 31 | { |
||
| 32 | return array( |
||
| 33 | array('config.update', array('similar_topics_sense', 1)), |
||
| 34 | array('config.add', array('pst_postgres_ts_name', $this->get_ts_name())), |
||
| 35 | array('if', array( |
||
| 36 | $this->db->get_sql_layer() === 'postgres', |
||
| 37 | array('custom', array(array($this, 'create_postgres_index'))), |
||
| 38 | )), |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | View Code Duplication | public function revert_data() |
|
| 51 | |||
| 52 | /** |
||
| 53 | * Create PostgreSQL FULLTEXT index for the topic_title |
||
| 54 | */ |
||
| 55 | public function create_postgres_index() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Drop the PostgreSQL FULLTEXT index on phpbb_topics.topic_title |
||
| 63 | */ |
||
| 64 | public function drop_postgres_changes() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get an instance of the similartopics POSTGRES driver |
||
| 77 | * |
||
| 78 | * @return \vse\similartopics\driver\postgres |
||
| 79 | */ |
||
| 80 | protected function get_driver() |
||
| 84 | |||
| 85 | protected function get_ts_name() |
||
| 89 | } |
||
| 90 |