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 | class Version20150812230500 extends AbstractMigrationChamilo |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @param Schema $schema |
||
19 | */ |
||
20 | public function up(Schema $schema) |
||
21 | { |
||
22 | $this->addSettingCurrent( |
||
23 | 'allow_coach_feedback_exercises', |
||
24 | null, |
||
25 | 'radio', |
||
26 | 'Session', |
||
27 | 'false', |
||
28 | 'AllowCoachFeedbackExercisesTitle', |
||
29 | 'AllowCoachFeedbackExercisesComment', |
||
30 | null, |
||
31 | null, |
||
32 | 1, |
||
33 | true, |
||
34 | false, |
||
35 | [ |
||
36 | ['value' => 'true', 'text' => 'Yes'], |
||
37 | ['value' => 'false', 'text' => 'No'] |
||
38 | ] |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param Schema $schema |
||
44 | */ |
||
45 | public function down(Schema $schema) |
||
46 | { |
||
47 | $entityManage = $this->getEntityManager(); |
||
48 | |||
49 | $deleteOptions = $entityManage->createQueryBuilder(); |
||
50 | |||
51 | $deleteOptions->delete('ChamiloCoreBundle:SettingsOptions', 'o') |
||
52 | ->andWhere( |
||
53 | $deleteOptions->expr()->in( |
||
54 | 'o.variable', |
||
55 | [ |
||
56 | 'allow_coach_feedback_exercises' |
||
57 | ] |
||
58 | ) |
||
59 | ); |
||
60 | $deleteOptions->getQuery()->execute(); |
||
61 | |||
62 | $deleteSettings = $entityManage->createQueryBuilder(); |
||
63 | $deleteSettings->delete('ChamiloCoreBundle:SettingsCurrent', 's') |
||
64 | ->andWhere( |
||
65 | $deleteSettings->expr()->in( |
||
66 | 's.variable', |
||
67 | [ |
||
68 | 'allow_coach_feedback_exercises' |
||
69 | ] |
||
70 | ) |
||
71 | ); |
||
72 | $deleteSettings->getQuery()->execute(); |
||
73 | } |
||
74 | |||
75 | } |
||
76 |