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.add', array('pst_postgres_ts_name', $this->get_ts_name())), |
||
34 | array('if', array( |
||
35 | $this->db->get_sql_layer() === 'postgres', |
||
36 | array('custom', array(array($this, 'create_postgres_index'))), |
||
37 | )), |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | View Code Duplication | public function revert_data() |
|
50 | |||
51 | /** |
||
52 | * Create PostgreSQL FULLTEXT index for the topic_title |
||
53 | */ |
||
54 | public function create_postgres_index() |
||
59 | |||
60 | /** |
||
61 | * Drop the PostgreSQL FULLTEXT index on phpbb_topics.topic_title |
||
62 | */ |
||
63 | public function drop_postgres_changes() |
||
73 | |||
74 | /** |
||
75 | * Get an instance of the similartopics POSTGRES driver |
||
76 | * |
||
77 | * @return \vse\similartopics\driver\postgres |
||
78 | */ |
||
79 | protected function get_driver() |
||
83 | |||
84 | protected function get_ts_name() |
||
88 | } |
||
89 |