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 |
||
| 10 | class FormFeedbackAdd extends Model |
||
| 11 | { |
||
| 12 | public $name; |
||
| 13 | public $email; |
||
| 14 | public $captcha; |
||
| 15 | public $message; |
||
| 16 | |||
| 17 | private $_hash; |
||
| 18 | |||
| 19 | private $_useCaptcha = true; |
||
| 20 | |||
| 21 | public function __construct($captcha = true) |
||
| 26 | |||
| 27 | |||
| 28 | /** |
||
| 29 | * Set user data if he is logged in |
||
| 30 | */ |
||
| 31 | public function before() |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Labels to display form |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function labels() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Rules to validate send form |
||
| 55 | */ |
||
| 56 | public function rules() |
||
| 70 | |||
| 71 | public function make() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Send email notification after feedback request creation |
||
| 98 | * @param $record |
||
| 99 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
| 100 | */ |
||
| 101 | private function sendEmail($record) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return string|null |
||
| 122 | */ |
||
| 123 | public function getHash() |
||
| 127 | } |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: