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 |
||
| 11 | class CodeigniterModel extends \CI_Model |
||
| 12 | { |
||
| 13 | use Traits\ModelTrait; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var \Rougin\Wildfire\Wildfire |
||
| 17 | */ |
||
| 18 | protected $wildfire; |
||
| 19 | |||
| 20 | 12 | public function __construct() |
|
| 26 | |||
| 27 | /** |
||
| 28 | * Returns all of the models from the database. |
||
| 29 | * |
||
| 30 | * @return array |
||
| 31 | */ |
||
| 32 | 3 | public function all() |
|
| 36 | |||
| 37 | /** |
||
| 38 | * Deletes the specified ID of the model from the database. |
||
| 39 | * |
||
| 40 | * @param integer $id |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | public function delete($id) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Finds the specified model from the database. |
||
| 50 | * |
||
| 51 | * @param integer $id |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | 3 | public function find($id) |
|
| 58 | |||
| 59 | /** |
||
| 60 | * Finds the specified model from the database by the given delimiters. |
||
| 61 | * |
||
| 62 | * @param array $delimiters |
||
| 63 | * @return mixed |
||
| 64 | */ |
||
| 65 | 3 | public function findBy(array $delimiters) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Returns all rows from the specified table. |
||
| 74 | * |
||
| 75 | * @return self |
||
| 76 | */ |
||
| 77 | 3 | public function get() |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Calls methods from this class in underscore case. |
||
| 84 | * |
||
| 85 | * @param string $method |
||
| 86 | * @param mixed $parameters |
||
| 87 | * @return mixed |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function __call($method, $parameters) |
|
| 102 | } |
||
| 103 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.