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 |
||
| 23 | class Indexer extends SearchDbConnected |
||
| 24 | { |
||
| 25 | const SQLITE_MAX_COMPOUND_SELECT = 100; |
||
| 26 | protected $filters = array( |
||
| 27 | 'DutchStopWords', |
||
| 28 | 'EnglishStopWords' |
||
| 29 | ); |
||
| 30 | protected $storageDir; |
||
| 31 | /** |
||
| 32 | * @var int |
||
| 33 | */ |
||
| 34 | protected $loggingStart; |
||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $log; |
||
| 39 | /** |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $lastLog; |
||
| 43 | |||
| 44 | const SEARCH_TEMP_DB = 'search_tmp.db'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Creates a new temporary search db, cleans it if it exists |
||
| 48 | * then calculates and stores the search index in this db |
||
| 49 | * and finally if indexing completed replaces the current search |
||
| 50 | * db with the temporary one. Returns the log in string format. |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | public function updateIndex() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Count how often a term is used in a document |
||
| 77 | * |
||
| 78 | * @param $documents |
||
| 79 | */ |
||
| 80 | public function createDocumentTermCount($documents) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Calculate the frequency index for a term with |
||
| 88 | * a field |
||
| 89 | */ |
||
| 90 | public function createDocumentTermFrequency() |
||
| 95 | |||
| 96 | |||
| 97 | /** |
||
| 98 | * Resets the entire index |
||
| 99 | */ |
||
| 100 | public function resetIndex() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Calculates the inverse document frequency for each |
||
| 116 | * term. This is a representation of how often a certain |
||
| 117 | * term is used in comparison to all terms. |
||
| 118 | */ |
||
| 119 | public function createInverseDocumentFrequency() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return int|mixed |
||
| 128 | */ |
||
| 129 | private function getTotalDocumentCount() |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Calculates the Term Field Length Norm. |
||
| 136 | * This is an index determining how important a |
||
| 137 | * term is, based on the total length of the field |
||
| 138 | * it comes from. |
||
| 139 | */ |
||
| 140 | public function createTermFieldLengthNorm() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Stores the time the indexing started in memory |
||
| 148 | */ |
||
| 149 | private function startLogging() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Adds a logline with the time since last log |
||
| 157 | * @param $string |
||
| 158 | */ |
||
| 159 | private function addLog($string) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Creates the SQLite \PDO object if it doesnt |
||
| 168 | * exist and returns it. |
||
| 169 | * @return \PDO |
||
| 170 | */ |
||
| 171 | View Code Duplication | protected function getSearchDbHandle() |
|
| 179 | |||
| 180 | /** |
||
| 181 | * Replaces the old search index database with the new one. |
||
| 182 | */ |
||
| 183 | public function replaceOldIndex() |
||
| 189 | } |
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: