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 |
||
| 23 | class TotpAuth extends Base implements PostAuthenticationProviderInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * User pin code. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $code = ''; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Private key. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $secret = ''; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get authentication provider name. |
||
| 41 | * |
||
| 42 | * @return string |
||
| 43 | */ |
||
| 44 | public function getName() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Authenticate the user. |
||
| 51 | * |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | public function authenticate() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Called before to prompt the user. |
||
| 63 | */ |
||
| 64 | public function beforeCode() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Set validation code. |
||
| 70 | * |
||
| 71 | * @param string $code |
||
| 72 | */ |
||
| 73 | public function setCode($code) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Generate secret. |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function generateSecret() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Set secret token. |
||
| 92 | * |
||
| 93 | * @param string $secret |
||
| 94 | */ |
||
| 95 | public function setSecret($secret) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get secret token. |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | public function getSecret() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get QR code url. |
||
| 112 | * |
||
| 113 | * @param string $label |
||
| 114 | * |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function getQrCodeUrl($label) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Get key url (empty if no url can be provided). |
||
| 130 | * |
||
| 131 | * @param string $label |
||
| 132 | * |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function getKeyUrl($label) |
|
| 145 | } |
||
| 146 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.