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 /** PgsqlDriverMicro */ |
||
| 19 | class PgsqlDriver extends Driver |
||
| 20 | { |
||
| 21 | /** @var string $tableSchema Table schema for postgres */ |
||
| 22 | protected $tableSchema = 'public'; |
||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * Driver constructor. |
||
| 27 | * |
||
| 28 | * @access public |
||
| 29 | * |
||
| 30 | * @param string $dsn DSN connection string |
||
| 31 | * @param array $config Configuration of connection |
||
| 32 | * @param array $options Other options |
||
| 33 | * |
||
| 34 | * @result void |
||
| 35 | * @throws Exception |
||
| 36 | */ |
||
| 37 | public function __construct($dsn, array $config = [], array $options = []) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Set current database |
||
| 48 | * |
||
| 49 | * @access public |
||
| 50 | * |
||
| 51 | * @param string $dbName Database name |
||
| 52 | * |
||
| 53 | * @return boolean |
||
| 54 | * @throws \InvalidArgumentException |
||
| 55 | */ |
||
| 56 | public function switchDatabase($dbName) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Info of database |
||
| 63 | * |
||
| 64 | * @access public |
||
| 65 | * |
||
| 66 | * @param string $dbName Database name |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | */ |
||
| 70 | public function infoDatabase($dbName) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * List tables in db |
||
| 77 | * |
||
| 78 | * @access public |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | public function listTables() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * List database names on this connection |
||
| 90 | * |
||
| 91 | * @access public |
||
| 92 | * @return mixed |
||
| 93 | */ |
||
| 94 | public function listDatabases() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Create a new table |
||
| 103 | * |
||
| 104 | * @param string $name Table name |
||
| 105 | * @param array $elements Table elements |
||
| 106 | * @param string $params Table params |
||
| 107 | * |
||
| 108 | * @return int |
||
| 109 | */ |
||
| 110 | public function createTable($name, array $elements = [], $params = '') |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Get array fields into table |
||
| 119 | * |
||
| 120 | * @access public |
||
| 121 | * |
||
| 122 | * @param string $table Table name |
||
| 123 | * |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | public function listFields($table) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Insert row into table |
||
| 145 | * |
||
| 146 | * @access public |
||
| 147 | * |
||
| 148 | * @param string $table Table name |
||
| 149 | * @param array $line Line or lines to added |
||
| 150 | * @param bool $multi Is multi rows |
||
| 151 | * |
||
| 152 | * @return bool |
||
| 153 | */ |
||
| 154 | public function insert($table, array $line = [], $multi = false) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Update row in table |
||
| 180 | * |
||
| 181 | * @access public |
||
| 182 | * |
||
| 183 | * @param string $table Table name |
||
| 184 | * @param array $elements Elements to update |
||
| 185 | * @param string $conditions Conditions for search |
||
| 186 | * |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | View Code Duplication | public function update($table, array $elements = [], $conditions = '') |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Exists element in the table by params |
||
| 214 | * |
||
| 215 | * @access public |
||
| 216 | * |
||
| 217 | * @param string $table Table name |
||
| 218 | * @param array $params Params array |
||
| 219 | * |
||
| 220 | * @return bool |
||
| 221 | */ |
||
| 222 | View Code Duplication | public function exists($table, array $params = []) |
|
| 236 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.