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 |
||
| 21 | class OAuthPasswordAuthentication extends AbstractAuthentication |
||
| 22 | { |
||
| 23 | const AUTHENTICATION_GRANT_TYPE = 'password'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Username for OAuth password authentication. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $username; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Password for OAuth password authentication. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $password; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Gets the value of username. |
||
| 41 | * |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | public function getUsername() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Sets the value of username. |
||
| 51 | * |
||
| 52 | * @param string $username Value to set |
||
| 53 | * |
||
| 54 | * @return self |
||
| 55 | */ |
||
| 56 | public function setUsername($username) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Gets the value of password. |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function getPassword() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Sets the value of password. |
||
| 75 | * |
||
| 76 | * @param string $password Value to set |
||
| 77 | * |
||
| 78 | * @return self |
||
| 79 | */ |
||
| 80 | public function setPassword($password) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | public function refreshAccessToken() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * {@inheritdoc} |
||
| 126 | */ |
||
| 127 | public function getAuthenticationTokens() |
||
| 160 | } |
||
| 161 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: