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 | trait ObjectTrait |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $tables = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Creates an object from the specified table and row. |
||
| 27 | * |
||
| 28 | * @param string $table |
||
| 29 | * @param object $row |
||
| 30 | * @param boolean $isForeignKey |
||
| 31 | * @return array |
||
| 32 | */ |
||
| 33 | 30 | protected function createObject($table, $row, $isForeignKey = false) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Finds the row from the specified ID or with the list of delimiters from |
||
| 68 | * the specified table. |
||
| 69 | * |
||
| 70 | * @param string $table |
||
| 71 | * @param array|integer $delimiters |
||
| 72 | * @param boolean $isForeignKey |
||
| 73 | * @return object|boolean |
||
| 74 | */ |
||
| 75 | abstract protected function find($table, $delimiters = [], $isForeignKey = false); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Returns the values from the model's properties. |
||
| 79 | * |
||
| 80 | * @param \CI_Model|\Rougin\Wildfire\CodeigniterModel $model |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | 30 | protected function getModelProperties($model) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Returns the values from the model's properties. |
||
| 104 | * |
||
| 105 | * @param \CI_Model|\Rougin\Wildfire\CodeigniterModel $model |
||
| 106 | * @param array $properties |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | 30 | public function getRelationshipProperties($model, array $properties) |
|
| 146 | |||
| 147 | /** |
||
| 148 | * Sets the foreign field of the column, if any. |
||
| 149 | * |
||
| 150 | * @param \CI_Model $model |
||
| 151 | * @param \Rougin\Describe\Column $column |
||
| 152 | * @param array $properties |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | 30 | protected function setForeignField(\CI_Model $model, Column $column, array $properties) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Gets the model class of the said table. |
||
| 176 | * |
||
| 177 | * @param string|object|null $table |
||
| 178 | * @param boolean $isForeignKey |
||
| 179 | * @return array |
||
| 180 | */ |
||
| 181 | 39 | protected function getModel($table = null, $isForeignKey = false) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Parses the table name from Describe class. |
||
| 206 | * |
||
| 207 | * @param string $table |
||
| 208 | * @param boolean $isForeignKey |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | abstract protected function getTableName($table, $isForeignKey = false); |
||
| 212 | } |
||
| 213 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: