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 DbSeeding extends DbExporter |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | public $database; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | public $filename; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $seedingStub; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | protected $customDb = false; |
||
31 | |||
32 | /** |
||
33 | * Set the database name. |
||
34 | * |
||
35 | * @param string $database |
||
36 | */ |
||
37 | public function __construct($database) |
||
41 | |||
42 | //end __construct() |
||
43 | |||
44 | /** |
||
45 | * Write the seed file. |
||
46 | */ |
||
47 | public function write() |
||
64 | |||
65 | //end write() |
||
66 | |||
67 | /** |
||
68 | * Convert the database tables to something usefull. |
||
69 | * |
||
70 | * @param null $database |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function convert($database = null) |
||
151 | |||
152 | //end convert() |
||
153 | |||
154 | /** |
||
155 | * Compile the current seedingStub with the seed template. |
||
156 | * |
||
157 | * @return mixed |
||
158 | */ |
||
159 | protected function compile($table) |
||
170 | |||
171 | //end compile() |
||
172 | |||
173 | private function insertPropertyAndValue($prop, $value) |
||
189 | |||
190 | //end insertPropertyAndValue() |
||
191 | |||
192 | /** |
||
193 | * @param $tableData |
||
194 | * |
||
195 | * @return bool |
||
196 | */ |
||
197 | public function hasTableData($tableData) |
||
201 | |||
202 | //end hasTableData() |
||
203 | }//end class |
||
204 |