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 string $dbname Name of file without '_db' and extention '.xml'. |
||
| 39 | */ |
||
| 40 | public function __construct($dbname) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return ConnectionManagement |
||
| 55 | */ |
||
| 56 | public function getConnectionManagement() |
||
| 60 | |||
| 61 | public function testConnection() |
||
| 65 | |||
| 66 | |||
| 67 | public function setCacheEngine(CacheEngineInterface $cache) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return CacheEngineInterface |
||
| 74 | * @throws NotAvailableException |
||
| 75 | */ |
||
| 76 | public function getCacheEngine() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Get the DBDriver |
||
| 86 | * @return DBDriverInterface |
||
| 87 | */ |
||
| 88 | public function getDbDriver() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @access public |
||
| 95 | * @param string $sql |
||
| 96 | * @param array $params |
||
| 97 | * @param int $ttl |
||
| 98 | * @return IteratorInterface |
||
| 99 | * @throws NotAvailableException |
||
| 100 | */ |
||
| 101 | public function getIterator($sql, $params = null, $ttl = null) |
||
| 126 | |||
| 127 | protected function getQueryKey($sql, $array) |
||
| 150 | |||
| 151 | public function getScalar($sql, $array = null) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @access public |
||
| 158 | * @param string $tablename |
||
| 159 | * @return array |
||
| 160 | */ |
||
| 161 | public function getAllFields($tablename) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @access public |
||
| 168 | * @param string $sql |
||
| 169 | * @param array $array |
||
| 170 | * @return Resource |
||
| 171 | */ |
||
| 172 | public function execSQL($sql, $array = null) |
||
| 176 | |||
| 177 | public function beginTransaction() |
||
| 181 | |||
| 182 | public function commitTransaction() |
||
| 186 | |||
| 187 | public function rollbackTransaction() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @access public |
||
| 194 | * @param IteratorInterface $it |
||
| 195 | * @param string $fieldPK |
||
| 196 | * @param string $fieldName |
||
| 197 | * @return Resource |
||
| 198 | */ |
||
| 199 | View Code Duplication | public function getArrayField(IteratorInterface $it, $fieldPK, $fieldName) |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @access public |
||
| 211 | * @return PDO |
||
| 212 | */ |
||
| 213 | public function getDBConnection() |
||
| 217 | |||
| 218 | /** |
||
| 219 | * |
||
| 220 | * @var DBFunctionsInterface |
||
| 221 | */ |
||
| 222 | protected $_dbFunction = null; |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Get a IDbFunctions class to execute Database specific operations. |
||
| 226 | * @return DBFunctionsInterface |
||
| 227 | */ |
||
| 228 | public function getDbFunctions() |
||
| 237 | |||
| 238 | public function setDriverAttribute($name, $value) |
||
| 242 | |||
| 243 | public function getDriverAttribute($name) |
||
| 247 | } |
||
| 248 |
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: