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 |
||
| 18 | class Wildfire |
||
| 19 | { |
||
| 20 | use DatabaseTrait, DescribeTrait, ObjectTrait, ResultTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param \CI_DB|null $database |
||
| 24 | * @param \CI_DB_result|null $query |
||
| 25 | */ |
||
| 26 | 24 | public function __construct($database = null, $query = null) |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Deletes the data from the specified table by the given delimiters. |
||
| 36 | * |
||
| 37 | * @param string|object $table |
||
| 38 | * @param integer|array $delimiters |
||
| 39 | * @return mixed |
||
| 40 | */ |
||
| 41 | 3 | public function delete($table, $delimiters) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Finds the row from the specified ID or with the list of delimiters from |
||
| 56 | * the specified table. |
||
| 57 | * |
||
| 58 | * @param object|string $table |
||
| 59 | * @param array|integer $delimiters |
||
| 60 | * @param boolean $isForeignKey |
||
| 61 | * @return object|boolean |
||
| 62 | */ |
||
| 63 | 6 | public function find($table, $delimiters = [], $isForeignKey = false) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Returns all rows from the specified table. |
||
| 90 | * |
||
| 91 | * @param object|string $table |
||
| 92 | * @return self |
||
| 93 | */ |
||
| 94 | 18 | public function get($table = '') |
|
| 119 | |||
| 120 | /** |
||
| 121 | * Calls methods from this class in underscore case. |
||
| 122 | * |
||
| 123 | * @param string $method |
||
| 124 | * @param mixed $parameters |
||
| 125 | * @return mixed |
||
| 126 | */ |
||
| 127 | 9 | View Code Duplication | public function __call($method, $parameters) |
| 140 | } |
||
| 141 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.