Conditions | 3 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
88 | public function handle(array $handlingSubject, array $response) |
||
89 | { |
||
90 | if (!isset($handlingSubject['payment']) |
||
91 | || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
||
92 | ) { |
||
93 | throw new InvalidArgumentException('Payment data object should be provided'); |
||
94 | } |
||
95 | |||
96 | $paymentDO = $handlingSubject['payment']; |
||
97 | |||
98 | $payment = $paymentDO->getPayment(); |
||
99 | |||
100 | $payPix = $response[self::RESPONSE_PIX]; |
||
101 | |||
102 | $qrCode = $payPix[self::PAYMENT_INFO_QR_CODE]; |
||
103 | |||
104 | $transactionId = $response[self::RESPONSE_PAYMENT_ID]; |
||
105 | |||
106 | $qrCodeImage = $this->configPix->generateImageQrCode($qrCode, $transactionId); |
||
107 | |||
108 | $payment->setAdditionalInformation( |
||
109 | self::PAYMENT_INFO_QR_CODE_IMAGE, |
||
110 | $qrCodeImage |
||
111 | ); |
||
112 | |||
113 | $payment->setAdditionalInformation( |
||
114 | self::PAYMENT_INFO_QR_CODE, |
||
115 | $qrCode |
||
116 | ); |
||
117 | |||
118 | $payment->setAdditionalInformation( |
||
119 | self::PAYMENT_INFO_CREATION_DATE_QRCODE, |
||
120 | $payPix[self::PAYMENT_INFO_CREATION_DATE_QRCODE] |
||
121 | ); |
||
122 | |||
123 | $payment->setAdditionalInformation( |
||
124 | self::PAYMENT_INFO_EXPIRATION_DATE_QRCODE, |
||
125 | $payPix[self::PAYMENT_INFO_EXPIRATION_DATE_QRCODE] |
||
126 | ); |
||
127 | |||
128 | $payment->setAdditionalInformation( |
||
129 | self::PAYMENT_INFO_PSP_CODE, |
||
130 | $payPix[self::PAYMENT_INFO_PSP_CODE] |
||
131 | ); |
||
132 | |||
133 | $payment->setTransactionId($transactionId); |
||
134 | $payment->setIsTransactionPending(1); |
||
135 | $payment->setIsTransactionClosed(false); |
||
136 | $payment->setAuthorizationTransaction($transactionId); |
||
137 | $payment->addTransaction(Transaction::TYPE_AUTH); |
||
138 | |||
139 | $order = $payment->getOrder(); |
||
140 | $order->setState(\Magento\Sales\Model\Order::STATE_NEW); |
||
141 | $order->setStatus('pending'); |
||
142 | $comment = __('Awaiting payment of the Pix.'); |
||
143 | $order->addStatusHistoryComment($comment, $payment->getOrder()->getStatus()); |
||
144 | } |
||
146 |