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 |
||
9 | class OracleBuilder extends Builder |
||
10 | { |
||
11 | /** |
||
12 | * @var \Yajra\Oci8\Schema\OracleAutoIncrementHelper |
||
13 | */ |
||
14 | public $helper; |
||
15 | |||
16 | /** |
||
17 | * @var \Yajra\Oci8\Schema\Comment |
||
18 | */ |
||
19 | public $comment; |
||
20 | |||
21 | /** |
||
22 | * @param Connection $connection |
||
23 | */ |
||
24 | public function __construct(Connection $connection) |
||
31 | |||
32 | /** |
||
33 | * Create a new table on the schema. |
||
34 | * |
||
35 | * @param string $table |
||
36 | * @param Closure $callback |
||
37 | * @return \Illuminate\Database\Schema\Blueprint |
||
38 | */ |
||
39 | View Code Duplication | public function create($table, Closure $callback) |
|
53 | |||
54 | /** |
||
55 | * Changes an existing table on the schema. |
||
56 | * |
||
57 | * @param string $table |
||
58 | * @param Closure $callback |
||
59 | * @return \Illuminate\Database\Schema\Blueprint |
||
60 | */ |
||
61 | View Code Duplication | public function table($table, Closure $callback) |
|
77 | |||
78 | /** |
||
79 | * Create a new command set with a Closure. |
||
80 | * |
||
81 | * @param string $table |
||
82 | * @param Closure $callback |
||
83 | * @return \Illuminate\Database\Schema\Blueprint |
||
84 | */ |
||
85 | protected function createBlueprint($table, Closure $callback = null) |
||
92 | |||
93 | /** |
||
94 | * Drop a table from the schema. |
||
95 | * |
||
96 | * @param string $table |
||
97 | * @return \Illuminate\Database\Schema\Blueprint |
||
98 | */ |
||
99 | public function drop($table) |
||
104 | |||
105 | /** |
||
106 | * Indicate that the table should be dropped if it exists. |
||
107 | * |
||
108 | * @return \Illuminate\Support\Fluent |
||
109 | */ |
||
110 | public function dropIfExists($table) |
||
115 | |||
116 | /** |
||
117 | * Determine if the given table exists. |
||
118 | * |
||
119 | * @param string $table |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function hasTable($table) |
||
131 | |||
132 | /** |
||
133 | * Get the column listing for a given table. |
||
134 | * |
||
135 | * @param string $table |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getColumnListing($table) |
||
147 | } |
||
148 |
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.