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 namespace Anomaly\Streams\Platform\Database\Migration; |
||
15 | class Migrator extends \Illuminate\Database\Migrations\Migrator |
||
16 | { |
||
17 | |||
18 | use DispatchesJobs; |
||
19 | |||
20 | /** |
||
21 | * The addon instance. |
||
22 | * |
||
23 | * @var Addon |
||
24 | */ |
||
25 | protected $addon = null; |
||
26 | |||
27 | /** |
||
28 | * The migration repository. |
||
29 | * |
||
30 | * @var MigrationRepository |
||
31 | */ |
||
32 | protected $repository; |
||
33 | |||
34 | /** |
||
35 | * Rolls all of the currently applied migrations back. |
||
36 | * |
||
37 | * @param array|string $paths |
||
38 | * @param bool $pretend |
||
39 | * @return array |
||
40 | */ |
||
41 | public function reset($paths = [], $pretend = false) |
||
47 | |||
48 | /** |
||
49 | * Rollback the last migration operation. |
||
50 | * |
||
51 | * @param array|string $paths |
||
52 | * @param array $options |
||
53 | * @return array |
||
54 | */ |
||
55 | public function rollback($paths = [], array $options = []) |
||
61 | |||
62 | /** |
||
63 | * Run "up" a migration instance. |
||
64 | * |
||
65 | * @param string $file |
||
66 | * @param int $batch |
||
67 | * @param bool $pretend |
||
68 | * @return void |
||
69 | */ |
||
70 | View Code Duplication | protected function runUp($file, $batch, $pretend) |
|
96 | |||
97 | /** |
||
98 | * Run "down" a migration instance. |
||
99 | * |
||
100 | * @param string $file |
||
101 | * @param object $migration |
||
102 | * @param bool $pretend |
||
103 | * @return void |
||
104 | */ |
||
105 | View Code Duplication | protected function runDown($file, $migration, $pretend) |
|
130 | |||
131 | /** |
||
132 | * Resolve a migration instance from a file. |
||
133 | * |
||
134 | * @param string $file |
||
135 | * @return object |
||
136 | */ |
||
137 | public function resolve($file) |
||
145 | |||
146 | /** |
||
147 | * Set the addon. |
||
148 | * |
||
149 | * @param Addon $addon |
||
150 | */ |
||
151 | public function setAddon(Addon $addon) |
||
157 | |||
158 | /** |
||
159 | * Get the addon. |
||
160 | * |
||
161 | * @return Addon |
||
162 | */ |
||
163 | public function getAddon() |
||
167 | } |
||
168 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.