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 Javascript extends Model |
||
| 12 | { |
||
| 13 | |||
| 14 | public function getSource() |
||
| 18 | |||
| 19 | public $id; |
||
| 20 | public $text; |
||
| 21 | |||
| 22 | public function afterUpdate() |
||
| 28 | |||
| 29 | View Code Duplication | public static function findCachedById($id) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @param mixed $text |
||
| 43 | */ |
||
| 44 | public function setText($text) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param mixed |
||
| 51 | */ |
||
| 52 | public function getText() |
||
| 56 | |||
| 57 | } |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.