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 |
||
15 | class DBDataset |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * Enter description here... |
||
20 | * |
||
21 | * @var ConnectionManagement |
||
22 | */ |
||
23 | protected $_connectionManagement; |
||
24 | |||
25 | /** |
||
26 | * |
||
27 | * @var DBDriverInterface |
||
28 | */ |
||
29 | private $_dbDriver = null; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * @var CacheEngineInterface |
||
34 | */ |
||
35 | protected $_cacheEngine; |
||
36 | |||
37 | /** |
||
38 | * @param ConnectionManagement|string $dbname Name of file without '_db' and extention '.xml'. |
||
39 | */ |
||
40 | public function __construct($dbname) |
||
58 | |||
59 | /** |
||
60 | * @return ConnectionManagement |
||
61 | */ |
||
62 | public function getConnectionManagement() |
||
66 | |||
67 | public function testConnection() |
||
71 | |||
72 | |||
73 | public function setCacheEngine(CacheEngineInterface $cache) |
||
77 | |||
78 | /** |
||
79 | * @return CacheEngineInterface |
||
80 | * @throws NotAvailableException |
||
81 | */ |
||
82 | public function getCacheEngine() |
||
89 | |||
90 | /** |
||
91 | * Get the DBDriver |
||
92 | * @return DBDriverInterface |
||
93 | */ |
||
94 | public function getDbDriver() |
||
98 | |||
99 | /** |
||
100 | * @access public |
||
101 | * @param string $sql |
||
102 | * @param array $params |
||
103 | * @param int $ttl |
||
104 | * @return IteratorInterface |
||
105 | * @throws NotAvailableException |
||
106 | */ |
||
107 | public function getIterator($sql, $params = null, $ttl = null) |
||
132 | |||
133 | protected function getQueryKey($sql, $array) |
||
156 | |||
157 | public function getScalar($sql, $array = null) |
||
161 | |||
162 | /** |
||
163 | * @access public |
||
164 | * @param string $tablename |
||
165 | * @return array |
||
166 | */ |
||
167 | public function getAllFields($tablename) |
||
171 | |||
172 | /** |
||
173 | * @access public |
||
174 | * @param string $sql |
||
175 | * @param array $array |
||
176 | * @return Resource |
||
177 | */ |
||
178 | public function execSQL($sql, $array = null) |
||
182 | |||
183 | public function beginTransaction() |
||
187 | |||
188 | public function commitTransaction() |
||
192 | |||
193 | public function rollbackTransaction() |
||
197 | |||
198 | /** |
||
199 | * @access public |
||
200 | * @param IteratorInterface $it |
||
201 | * @param string $fieldPK |
||
202 | * @param string $fieldName |
||
203 | * @return Resource |
||
204 | */ |
||
205 | View Code Duplication | public function getArrayField(IteratorInterface $it, $fieldPK, $fieldName) |
|
214 | |||
215 | /** |
||
216 | * @access public |
||
217 | * @return PDO |
||
218 | */ |
||
219 | public function getDBConnection() |
||
223 | |||
224 | /** |
||
225 | * |
||
226 | * @var DBFunctionsInterface |
||
227 | */ |
||
228 | protected $_dbFunction = null; |
||
229 | |||
230 | /** |
||
231 | * Get a IDbFunctions class to execute Database specific operations. |
||
232 | * @return DBFunctionsInterface |
||
233 | */ |
||
234 | public function getDbFunctions() |
||
243 | |||
244 | public function setDriverAttribute($name, $value) |
||
248 | |||
249 | public function getDriverAttribute($name) |
||
253 | } |
||
254 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: