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 |
||
10 | class FileDateMigrationCreator extends Creator implements MigrationCreator |
||
11 | { |
||
12 | /** |
||
13 | * Create a migration file. |
||
14 | * |
||
15 | * @param string $name |
||
16 | * @param string $create |
||
17 | * |
||
18 | * @return string |
||
19 | */ |
||
20 | public function create($name, $create = false) |
||
42 | |||
43 | /** |
||
44 | * Return StudlyCase class name. |
||
45 | * |
||
46 | * @param string $name |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | protected function getClassName($name) |
||
54 | |||
55 | /** |
||
56 | * Get stub with appropriate class name/table name. |
||
57 | * |
||
58 | * @param string $className |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | protected function getStub($className, $create) |
||
70 | |||
71 | /** |
||
72 | * Populate stub with class name and table name. |
||
73 | * |
||
74 | * @param string $stub |
||
75 | * @param string $className |
||
76 | * @param string $create |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | protected function populateStub($stub, $className, $create) |
||
88 | |||
89 | /** |
||
90 | * Get the full path to save file to. |
||
91 | * |
||
92 | * @param string $name |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | protected function getSavePath($name) |
||
102 | |||
103 | /** |
||
104 | * Build file name for migration. |
||
105 | * |
||
106 | * @param string $name |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | protected function buildFileName($name) |
||
114 | |||
115 | /** |
||
116 | * Get the date prefix for the migration. |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | protected function getDatePrefix() |
||
124 | } |
||
125 |