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 |
||
| 13 | class Query implements \Inji\Db\DriverQuery { |
||
| 14 | /** |
||
| 15 | * @var \Inji\Db\InjiStorage |
||
| 16 | */ |
||
| 17 | public $connection; |
||
| 18 | public $whereArray = []; |
||
| 19 | public $table = []; |
||
| 20 | public $dbOptions = []; |
||
| 21 | |||
| 22 | public function __construct($connection) { |
||
| 25 | |||
| 26 | public function setDbOption($name, $value) { |
||
| 29 | |||
| 30 | View Code Duplication | public function where($col, $value = true, $comparision = '=', $concatenation = 'AND') { |
|
| 38 | |||
| 39 | public function setTable($tableName) { |
||
| 42 | |||
| 43 | public function select($tableName = null) { |
||
| 49 | |||
| 50 | public function insert(string $tableName, array $values) { |
||
| 56 | |||
| 57 | public function update(string $tableName, array $values) { |
||
| 63 | |||
| 64 | public function delete(string $tableName='') { |
||
| 70 | |||
| 71 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: