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 |
||
| 17 | class Postgres82 extends Postgres83 |
||
|
1 ignored issue
–
show
|
|||
| 18 | { |
||
| 19 | public $major_version = 8.2; |
||
| 20 | |||
| 21 | // Select operators |
||
| 22 | public $selectOps = [ |
||
| 23 | '=' => 'i', |
||
| 24 | '!=' => 'i', |
||
| 25 | '<' => 'i', |
||
| 26 | '>' => 'i', |
||
| 27 | '<=' => 'i', |
||
| 28 | '>=' => 'i', |
||
| 29 | '<<' => 'i', |
||
| 30 | '>>' => 'i', |
||
| 31 | '<<=' => 'i', |
||
| 32 | '>>=' => 'i', |
||
| 33 | 'LIKE' => 'i', |
||
| 34 | 'NOT LIKE' => 'i', |
||
| 35 | 'ILIKE' => 'i', |
||
| 36 | 'NOT ILIKE' => 'i', |
||
| 37 | 'SIMILAR TO' => 'i', |
||
| 38 | 'NOT SIMILAR TO' => 'i', |
||
| 39 | '~' => 'i', |
||
| 40 | '!~' => 'i', |
||
| 41 | '~*' => 'i', |
||
| 42 | '!~*' => 'i', |
||
| 43 | 'IS NULL' => 'p', |
||
| 44 | 'IS NOT NULL' => 'p', |
||
| 45 | 'IN' => 'x', |
||
| 46 | 'NOT IN' => 'x', |
||
| 47 | ]; |
||
| 48 | |||
| 49 | // Database functions |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Returns table locks information in the current database. |
||
| 53 | * |
||
| 54 | * @return \PHPPgAdmin\ADORecordSet A recordset |
||
| 55 | */ |
||
| 56 | View Code Duplication | public function getLocks() |
|
| 73 | |||
| 74 | // Sequence functions |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Rename a sequence. |
||
| 78 | * |
||
| 79 | * @param \PHPPgAdmin\ADORecordSet $seqrs The sequence RecordSet returned by getSequence() |
||
| 80 | * @param string $name The new name for the sequence |
||
| 81 | * |
||
| 82 | * @return int 0 if operation was successful |
||
| 83 | */ |
||
| 84 | View Code Duplication | public function alterSequenceName($seqrs, $name) |
|
| 101 | |||
| 102 | // View functions |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Rename a view. |
||
| 106 | * |
||
| 107 | * @param \PHPPgAdmin\ADORecordSet $vwrs The view recordSet returned by getView() |
||
| 108 | * @param string $name The new view's name |
||
| 109 | * |
||
| 110 | * @return int -1 if Failed |
||
| 111 | */ |
||
| 112 | View Code Duplication | public function alterViewName($vwrs, $name) |
|
| 130 | |||
| 131 | // Trigger functions |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Grabs a list of triggers on a table. |
||
| 135 | * |
||
| 136 | * @param string $table The name of a table whose triggers to retrieve |
||
| 137 | * |
||
| 138 | * @return \PHPPgAdmin\ADORecordSet A recordset |
||
| 139 | */ |
||
| 140 | public function getTriggers($table = '') |
||
| 162 | |||
| 163 | // Function functions |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Returns all details for a particular function. |
||
| 167 | * |
||
| 168 | * @param int $function_oid |
||
| 169 | * |
||
| 170 | * @return \PHPPgAdmin\ADORecordSet Function info |
||
| 171 | * |
||
| 172 | * @internal param string The $func name of the function to retrieve |
||
| 173 | */ |
||
| 174 | public function getFunction($function_oid) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Creates a new function. |
||
| 207 | * |
||
| 208 | * @param string $funcname The name of the function to create |
||
| 209 | * @param string $args A comma separated string of types |
||
| 210 | * @param string $returns The return type |
||
| 211 | * @param string $definition The definition for the new function |
||
| 212 | * @param string $language The language the function is written for |
||
| 213 | * @param array $flags An array of optional flags |
||
| 214 | * @param bool $setof True if it returns a set, false otherwise |
||
| 215 | * @param float $cost cost the planner should use in the function execution step |
||
| 216 | * @param int $rows number of rows planner should estimate will be returned |
||
| 217 | * @param string $comment The comment on the function |
||
| 218 | * @param bool $replace (optional) True if OR REPLACE, false for normal |
||
| 219 | * |
||
| 220 | * @return bool|int 0 success |
||
| 221 | */ |
||
| 222 | public function createFunction($funcname, $args, $returns, $definition, $language, $flags, $setof, $cost, $rows, $comment, $replace = false) |
||
| 298 | |||
| 299 | // Index functions |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Clusters an index. |
||
| 303 | * |
||
| 304 | * @param string $table The table the index is on |
||
| 305 | * @param string $index The name of the index |
||
| 306 | * |
||
| 307 | * @return array 0 if operation was successful |
||
| 308 | */ |
||
| 309 | View Code Duplication | public function clusterIndex($table = '', $index = '') |
|
| 333 | |||
| 334 | // Operator functions |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Returns all details for a particular operator. |
||
| 338 | * |
||
| 339 | * @param int $operator_oid The oid of the operator |
||
| 340 | * |
||
| 341 | * @return \PHPPgAdmin\ADORecordSet Function info |
||
| 342 | */ |
||
| 343 | public function getOperator($operator_oid) |
||
| 371 | |||
| 372 | // Operator Class functions |
||
| 373 | |||
| 374 | /** |
||
| 375 | * Gets all opclasses. |
||
| 376 | * |
||
| 377 | * @return \PHPPgAdmin\ADORecordSet A recordset |
||
| 378 | */ |
||
| 379 | public function getOpClasses() |
||
| 401 | |||
| 402 | // Capabilities |
||
| 403 | |||
| 404 | public function hasCreateTableLikeWithIndexes() |
||
| 408 | |||
| 409 | public function hasEnumTypes() |
||
| 413 | |||
| 414 | public function hasFTS() |
||
| 418 | |||
| 419 | public function hasFunctionCosting() |
||
| 423 | |||
| 424 | public function hasFunctionGUC() |
||
| 428 | |||
| 429 | public function hasVirtualTransactionId() |
||
| 433 | } |
||
| 434 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.