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 |
||
| 36 | class Postdispatch implements ObserverInterface |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var ResponseFactory |
||
| 40 | */ |
||
| 41 | private $responseFactory; |
||
| 42 | /** |
||
| 43 | * @var UrlInterface |
||
| 44 | */ |
||
| 45 | private $url; |
||
| 46 | /** |
||
| 47 | * @var Customer |
||
| 48 | */ |
||
| 49 | private $customerGetter; |
||
| 50 | /** |
||
| 51 | * @var IsUsingTwoFactor |
||
| 52 | */ |
||
| 53 | private $isUsingTwoFactor; |
||
| 54 | /** |
||
| 55 | * @var IsVerified |
||
| 56 | */ |
||
| 57 | private $isVerified; |
||
| 58 | /** |
||
| 59 | * @var TwoFactorUrls |
||
| 60 | */ |
||
| 61 | private $twoFactorUrls; |
||
| 62 | /** |
||
| 63 | * @var Session |
||
| 64 | */ |
||
| 65 | private $customerSession; |
||
| 66 | /** |
||
| 67 | * @var CustomerAdmin |
||
| 68 | */ |
||
| 69 | private $customerAdmin; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Predispatch constructor. |
||
| 73 | * |
||
| 74 | * @param ResponseFactory $responseFactory |
||
| 75 | * @param UrlInterface $url |
||
| 76 | * @param Customer $customerGetter |
||
| 77 | * @param IsVerified $isVerified |
||
| 78 | * @param Session $customerSession |
||
| 79 | * @param IsUsingTwoFactor $isUsingTwoFactor |
||
| 80 | * @param TwoFactorUrls $twoFactorUrls |
||
| 81 | * @param CustomerAdmin $customerAdmin |
||
| 82 | */ |
||
| 83 | public function __construct( |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param Observer $observer |
||
| 105 | * |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function execute(Observer $observer) |
|
| 125 | |||
| 126 | private function isTwoFactorEnabled() |
||
| 130 | |||
| 131 | private function shouldTheCustomerBeRedirected() |
||
| 148 | |||
| 149 | View Code Duplication | private function areWeOnAnAllowedPage() |
|
| 162 | |||
| 163 | private function hasTwoFactorBeenChecked() |
||
| 170 | |||
| 171 | private function redirectToTwoFactorCheck(Action $controller) |
||
| 177 | } |
||
| 178 |