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 |
||
| 15 | class ResetPassword extends Model |
||
| 16 | { |
||
| 17 | public $password; |
||
| 18 | public $retypePassword; |
||
| 19 | /** |
||
| 20 | * @var User |
||
| 21 | */ |
||
| 22 | private $_user; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Creates a form model given a token. |
||
| 26 | * |
||
| 27 | * @param string $token |
||
| 28 | * @param array $config name-value pairs that will be used to initialize the object properties |
||
| 29 | * @throws InvalidParamException if token is empty or not valid |
||
| 30 | */ |
||
| 31 | public function __construct($token, $config = []) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @inheritdoc |
||
| 52 | */ |
||
| 53 | public function rules() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Resets password. |
||
| 64 | * |
||
| 65 | * @return boolean if password was reset. |
||
| 66 | */ |
||
| 67 | public function resetPassword() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Finds out if password reset token is valid |
||
| 78 | * |
||
| 79 | * @param string $token password reset token |
||
| 80 | * @return boolean |
||
| 81 | */ |
||
| 82 | View Code Duplication | public static function isPasswordResetTokenValid($token) |
|
| 92 | } |
||
| 93 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: