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 |
||
14 | View Code Duplication | class Version20131223134044_AddNoticeDateStart extends AbstractMigration |
|
15 | { |
||
16 | public function up(Schema $schema) |
||
17 | { |
||
18 | // create temp table from new structure |
||
19 | $this->addSql('CREATE TABLE "_new" ( |
||
20 | id INTEGER NOT NULL, |
||
21 | message TEXT NOT NULL, |
||
22 | date_closed DATETIME DEFAULT NULL, |
||
23 | date_created DATETIME NOT NULL, |
||
24 | date_start DATETIME NOT NULL, |
||
25 | lifetime INTEGER NOT NULL, |
||
26 | status INTEGER NOT NULL, |
||
27 | PRIMARY KEY(id) |
||
28 | )'); |
||
29 | |||
30 | $this->addSql(' |
||
31 | INSERT INTO |
||
32 | "_new" |
||
33 | SELECT |
||
34 | id, message, date_closed, date_created, date_created, lifetime, status |
||
35 | FROM |
||
36 | "notice" |
||
37 | '); |
||
38 | // rename new to origin and drop origin |
||
39 | $this->addSql('ALTER TABLE notice RENAME TO _origin'); |
||
40 | $this->addSql('ALTER TABLE _new RENAME TO notice'); |
||
41 | $this->addSql('DROP TABLE _origin'); |
||
42 | |||
43 | $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_start)'); |
||
44 | } |
||
45 | |||
46 | public function down(Schema $schema) |
||
73 | } |
||
74 |