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 |
||
29 | class TableLoad |
||
30 | { |
||
31 | |||
32 | /** |
||
33 | * loadTableFromArray |
||
34 | * |
||
35 | * @param string $table name of table to load without prefix |
||
36 | * @param array $data array of rows to insert |
||
37 | * Each element of the outer array represents a single table row. |
||
38 | * Each row is an associative array in 'column' => 'value' format. |
||
39 | * |
||
40 | * @return int number of rows inserted |
||
41 | */ |
||
42 | public static function loadTableFromArray($table, $data) |
||
76 | |||
77 | /** |
||
78 | * loadTableFromYamlFile |
||
79 | * |
||
80 | * @param string $table name of table to load without prefix |
||
81 | * @param string $yamlFile name of file containing data dump in YAML format |
||
82 | * |
||
83 | * @return int number of rows inserted |
||
84 | */ |
||
85 | View Code Duplication | public static function loadTableFromYamlFile($table, $yamlFile) |
|
86 | { |
||
87 | $count = 0; |
||
88 | |||
89 | $data = Yaml::loadWrapped($yamlFile); // work with phpmyadmin YAML dumps |
||
90 | if (false !== $data) { |
||
91 | $count = static::loadTableFromArray($table, $data); |
||
92 | } |
||
93 | |||
94 | return $count; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * truncateTable - empty a database table |
||
99 | * |
||
100 | * @param string $table name of table to truncate |
||
101 | * |
||
102 | * @return int number of affected rows |
||
103 | */ |
||
104 | public static function truncateTable($table) |
||
117 | |||
118 | /** |
||
119 | * countRows - get count of rows in a table |
||
120 | * |
||
121 | * @param string $table name of table to count |
||
122 | * @param \CriteriaElement $criteria optional criteria |
||
123 | * |
||
124 | * @return int number of rows |
||
125 | */ |
||
126 | public static function countRows($table, $criteria = null) |
||
142 | |||
143 | /** |
||
144 | * extractRows - get rows, all or a subset, from a table as an array |
||
145 | * |
||
146 | * @param string $table name of table to count |
||
147 | * @param \CriteriaElement $criteria optional criteria |
||
148 | * @param string[] $skipColumns do not include columns in this list |
||
149 | * |
||
150 | * @return array of table rows |
||
151 | */ |
||
152 | public static function extractRows($table, $criteria = null, $skipColumns = array()) |
||
182 | |||
183 | /** |
||
184 | * Save table data to a YAML file |
||
185 | * |
||
186 | * @param string $table name of table to load without prefix |
||
187 | * @param string $yamlFile name of file containing data dump in YAML format |
||
188 | * @param \CriteriaElement $criteria optional criteria |
||
189 | * @param string[] $skipColumns do not include columns in this list |
||
190 | * |
||
191 | * @return bool true on success, false on error |
||
192 | */ |
||
193 | View Code Duplication | public static function saveTableToYamlFile($table, $yamlFile, $criteria = null, $skipColumns = array()) |
|
201 | } |
||
202 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.