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 |
||
| 37 | class TokenController extends Controller { |
||
| 38 | |||
| 39 | /** @var UserManager */ |
||
| 40 | private $userManager; |
||
| 41 | |||
| 42 | /** @var IProvider */ |
||
| 43 | private $tokenProvider; |
||
| 44 | |||
| 45 | /** @var TwoFactorAuthManager */ |
||
| 46 | private $twoFactorAuthManager; |
||
| 47 | |||
| 48 | /** @var ISecureRandom */ |
||
| 49 | private $secureRandom; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $appName |
||
| 53 | * @param IRequest $request |
||
| 54 | * @param Manager $userManager |
||
| 55 | * @param DefaultTokenProvider $tokenProvider |
||
| 56 | * @param ISecureRandom $secureRandom |
||
| 57 | */ |
||
| 58 | View Code Duplication | public function __construct($appName, IRequest $request, UserManager $userManager, IProvider $tokenProvider, TwoFactorAuthManager $twoFactorAuthManager, ISecureRandom $secureRandom) { |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Generate a new access token clients can authenticate with |
||
| 68 | * |
||
| 69 | * @PublicPage |
||
| 70 | * @NoCSRFRequired |
||
| 71 | * |
||
| 72 | * @param string $user |
||
| 73 | * @param string $password |
||
| 74 | * @param string $name the name of the client |
||
| 75 | * @return JSONResponse |
||
| 76 | */ |
||
| 77 | public function generateToken($user, $password, $name = 'unknown client') { |
||
| 103 | |||
| 104 | } |
||
| 105 |
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.