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 |
||
| 7 | class FormCommentUpdate extends Model |
||
| 8 | { |
||
| 9 | public $message; |
||
| 10 | public $guestName; |
||
| 11 | |||
| 12 | /** @var Apps\ActiveRecord\CommentPost|Apps\ActiveRecord\CommentAnswer $_record */ |
||
| 13 | private $_record; |
||
| 14 | private $type; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * FormCommentUpdate constructor. Pass record inside the model. |
||
| 18 | * @param Apps\ActiveRecord\CommentPost|Apps\ActiveRecord\CommentAnswer $record |
||
| 19 | */ |
||
| 20 | public function __construct($record, $type = 'comment') |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Set default values from active record data |
||
| 28 | */ |
||
| 29 | public function before() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Labels to display in view |
||
| 37 | */ |
||
| 38 | public function labels() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Validation rules for comment body |
||
| 48 | */ |
||
| 49 | View Code Duplication | public function rules() |
|
| 57 | |||
| 58 | /** |
||
| 59 | * Save updated data to database |
||
| 60 | */ |
||
| 61 | public function make() |
||
| 67 | |||
| 68 | public function getCommentId() |
||
| 77 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.