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 PostgreSQLDriver extends DBDriverAbstract{ |
||
| 18 | |||
| 19 | protected $dialect = 'pgsql'; |
||
| 20 | protected $quotes = ['"', '"']; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Holds the database resource object |
||
| 24 | * |
||
| 25 | * @var resource |
||
| 26 | */ |
||
| 27 | protected $db; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Establishes a database connection and returns the connection object |
||
| 31 | * |
||
| 32 | * @return \chillerlan\Database\Drivers\DBDriverInterface |
||
| 33 | * @throws \chillerlan\Database\Drivers\DBDriverException |
||
| 34 | */ |
||
| 35 | public function connect():DBDriverInterface{ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Closes a database connection |
||
| 69 | * |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | public function disconnect():bool{ |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Returns info about the used php client |
||
| 78 | * |
||
| 79 | * @return string php's database client string |
||
| 80 | */ |
||
| 81 | public function getClientInfo():string{ |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Returns info about the database server |
||
| 89 | * |
||
| 90 | * @return string database's serverinfo string |
||
| 91 | */ |
||
| 92 | public function getServerInfo():string{ |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param $data |
||
| 100 | * |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public function escape($data){ |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param $result |
||
| 109 | * @param string|null $index |
||
| 110 | * @param bool $assoc |
||
| 111 | * |
||
| 112 | * @return bool|\chillerlan\Database\DBResult |
||
| 113 | */ |
||
| 114 | protected function __getResult($result, string $index = null, bool $assoc = true){ |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string $sql |
||
| 158 | * @param string|null $index |
||
| 159 | * @param bool $assoc |
||
| 160 | * |
||
| 161 | * @return bool|\chillerlan\Database\DBResult |
||
| 162 | */ |
||
| 163 | protected function __raw(string $sql, string $index = null, bool $assoc = true){ |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $sql |
||
| 169 | * @param array $values |
||
| 170 | * @param string|null $index |
||
| 171 | * @param bool $assoc |
||
| 172 | * |
||
| 173 | * @return bool|\chillerlan\Database\DBResult |
||
| 174 | */ |
||
| 175 | protected function __prepared(string $sql, array $values = [], string $index = null, bool $assoc = true){ |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param string $sql |
||
| 183 | * @param array $values |
||
| 184 | * |
||
| 185 | * @return bool |
||
| 186 | */ |
||
| 187 | View Code Duplication | protected function __multi(string $sql, array $values){ |
|
| 196 | |||
| 197 | /** |
||
| 198 | * @param string $sql |
||
| 199 | * @param array $data |
||
| 200 | * @param $callback |
||
| 201 | * |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | View Code Duplication | protected function __multi_callback(string $sql, array $data, $callback){ |
|
| 213 | |||
| 214 | /** |
||
| 215 | * @param string $sql |
||
| 216 | * |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | protected function replaceParams(string $sql):string{ |
||
| 226 | |||
| 227 | } |
||
| 228 |
As per the PSR-2 coding standard, the
break(or other terminating) statement must be on a line of its own.To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.