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 Verify extends AbstractController |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * @var TwoFactorSecret |
||
| 41 | */ |
||
| 42 | private $twoFactorSecret; |
||
| 43 | /** |
||
| 44 | * @var GoogleVerify |
||
| 45 | */ |
||
| 46 | private $verify; |
||
| 47 | /** |
||
| 48 | * @var IsVerified |
||
| 49 | */ |
||
| 50 | private $isVerified; |
||
| 51 | /** |
||
| 52 | * @var Session |
||
| 53 | */ |
||
| 54 | private $adminSession; |
||
| 55 | /** |
||
| 56 | * @var Fetcher |
||
| 57 | */ |
||
| 58 | private $fetcher; |
||
|
|
|||
| 59 | |||
| 60 | /** |
||
| 61 | * Verify constructor. |
||
| 62 | * |
||
| 63 | * @param Context $context |
||
| 64 | * @param UserAdmin $userAdmin |
||
| 65 | * @param AdminUser $adminGetter |
||
| 66 | * @param Fetcher $fetcher |
||
| 67 | * @param IsUsingTwoFactor $isUsingTwoFactor |
||
| 68 | * @param TwoFactorSecret $twoFactorSecret |
||
| 69 | * @param GoogleVerify $verify |
||
| 70 | * @param IsVerified $isVerified |
||
| 71 | * @param Session $adminSession |
||
| 72 | * @param Fetcher $fetcher |
||
| 73 | */ |
||
| 74 | 6 | View Code Duplication | public function __construct( |
| 92 | |||
| 93 | /** |
||
| 94 | * Dispatch request |
||
| 95 | * |
||
| 96 | * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface |
||
| 97 | * @throws \Magento\Framework\Exception\NotFoundException |
||
| 98 | */ |
||
| 99 | 6 | View Code Duplication | public function execute() |
| 116 | |||
| 117 | 4 | private function verifySecret($adminUser, $postedSecret) |
|
| 128 | |||
| 129 | 2 | View Code Duplication | private function handleError() |
| 137 | |||
| 138 | 2 | private function addErrorMessage() |
|
| 142 | |||
| 143 | 2 | private function handleSuccess() |
|
| 150 | |||
| 151 | public function _isAllowed() |
||
| 155 | } |
||
| 156 |