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 Express extends \Magento\Framework\App\Action\Action | ||
| 37 | { | ||
| 38 | /** | ||
| 39 | * Checkout session | ||
| 40 | * | ||
| 41 | * @var \Magento\Checkout\Model\Session | ||
| 42 | */ | ||
| 43 | protected $checkoutSession; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * PAYONE request model | ||
| 47 | * | ||
| 48 | * @var \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress | ||
| 49 | */ | ||
| 50 | protected $genericRequest; | ||
| 51 | |||
| 52 | /** | ||
| 53 | * PayPal payment model | ||
| 54 | * | ||
| 55 | * @var \Payone\Core\Model\Methods\Paypal | ||
| 56 | */ | ||
| 57 | protected $paypalPayment; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Checkout helper | ||
| 61 | * | ||
| 62 | * @var \Magento\Checkout\Helper\Data | ||
| 63 | */ | ||
| 64 | protected $checkoutHelper; | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Customer session | ||
| 68 | * | ||
| 69 | * @var \Magento\Customer\Model\Session | ||
| 70 | */ | ||
| 71 | protected $customerSession; | ||
| 72 | |||
| 73 | /** | ||
| 74 | * PAYONE payment helper | ||
| 75 | * | ||
| 76 | * @var \Payone\Core\Helper\Payment | ||
| 77 | */ | ||
| 78 | protected $paymentHelper; | ||
| 79 | |||
| 80 | /** | ||
| 81 | * Constructor | ||
| 82 | * | ||
| 83 | * @param \Magento\Framework\App\Action\Context $context | ||
| 84 | * @param \Magento\Checkout\Model\Session $checkoutSession | ||
| 85 | * @param \Payone\Core\Model\Api\Request\Genericpayment\PayPalExpress $genericRequest | ||
| 86 | * @param \Payone\Core\Model\Methods\Paypal $paypalPayment | ||
| 87 | * @param \Magento\Checkout\Helper\Data $checkoutHelper | ||
| 88 | * @param \Magento\Customer\Model\Session $customerSession | ||
| 89 | * @param \Payone\Core\Helper\Payment $paymentHelper | ||
| 90 | */ | ||
| 91 | public function __construct( | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Determine if a logged in customer is required for an express checkout | ||
| 111 | * For example needed for virtual products ( download-products etc. ) | ||
| 112 | * | ||
| 113 | * @param Quote $oQuote | ||
| 114 | * @return bool | ||
| 115 | */ | ||
| 116 | protected function loginNeededForExpressCheckout(Quote $oQuote) | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Redirect to payment-provider or to success page | ||
| 132 | * | ||
| 133 | * @return void | ||
| 134 | */ | ||
| 135 | public function execute() | ||
| 168 | } | ||
| 169 | 
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.