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 |
||
| 8 | class Builder { |
||
| 9 | public $connection = 'default'; |
||
| 10 | public $modelName = ''; |
||
| 11 | public $whereArray = []; |
||
| 12 | public $dbOptions = []; |
||
| 13 | /** |
||
| 14 | * @var \Inji\App |
||
| 15 | */ |
||
| 16 | public $app; |
||
| 17 | |||
| 18 | public function __construct(string $modelName, App $app = null) { |
||
| 26 | |||
| 27 | public function connection($connection = 'default') { |
||
| 31 | |||
| 32 | public function getConnection() { |
||
| 35 | |||
| 36 | public function model(string $modelName) { |
||
| 40 | |||
| 41 | View Code Duplication | public function where($col, $value = true, $comparision = '=', $concatenation = 'AND') { |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @return \Inji\Db\DriverQuery |
||
| 52 | */ |
||
| 53 | public function createQuery() { |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param array $options |
||
| 70 | * @return bool||\Inji\Model |
||
| 71 | */ |
||
| 72 | public function get($options = []) { |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param array $options |
||
| 83 | * @return bool||\Inji\Model |
||
| 84 | */ |
||
| 85 | public function getList($options = []) { |
||
| 93 | |||
| 94 | public function insert($values) { |
||
| 98 | |||
| 99 | public function update($values) { |
||
| 103 | |||
| 104 | public function delete() { |
||
| 108 | |||
| 109 | public function setDbOption($optionName, $value) { |
||
| 113 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.