| Conditions | 5 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 37 |
| 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 |
||
| 128 | public function handle(array $handlingSubject, array $response) |
||
| 129 | { |
||
| 130 | if (!isset($handlingSubject['payment']) |
||
| 131 | || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
||
| 132 | ) { |
||
| 133 | throw new InvalidArgumentException('Payment data object should be provided'); |
||
| 134 | } |
||
| 135 | |||
| 136 | $paymentDO = $handlingSubject['payment']; |
||
| 137 | |||
| 138 | $payment = $paymentDO->getPayment(); |
||
| 139 | $payBoleto = $response[self::RESPONSE_BOLETO]; |
||
| 140 | |||
| 141 | $payment->setAdditionalInformation( |
||
| 142 | self::PAYMENT_INFO_BOLETO_LINE_CODE, |
||
| 143 | $payBoleto[self::RESPONSE_BOLETO_TYPEFUL_LINE] |
||
| 144 | ); |
||
| 145 | |||
| 146 | $payment->setAdditionalInformation( |
||
| 147 | self::PAYMENT_INFO_BOLETO_EXPIRATION_DATE, |
||
| 148 | $payBoleto[self::RESPONSE_BOLETO_EXPIRATION_DATE] |
||
| 149 | ); |
||
| 150 | |||
| 151 | $payment->setAdditionalInformation( |
||
| 152 | self::PAYMENT_INFO_BOLETO_OUR_NUMBER, |
||
| 153 | $payBoleto[self::RESPONSE_BOLETO_DOCUMENT_NUMBER] |
||
| 154 | ); |
||
| 155 | |||
| 156 | $payment->setAdditionalInformation( |
||
| 157 | self::PAYMENT_INFO_BOLETO_DOCUMENT_NUMBER, |
||
| 158 | $payBoleto[self::RESPONSE_BOLETO_OUR_NUMBER] |
||
| 159 | ); |
||
| 160 | |||
| 161 | $links = $payBoleto[self::RESPONSE_BOLETO_LINKS]; |
||
| 162 | foreach ($links as $link) { |
||
| 163 | if ($link[self::RESPONSE_BOLETO_LINKS_REL] === self::RESPONSE_BOLETO_LINKS_REL_PDF) { |
||
| 164 | $relativeLinkToPDF = $link[self::RESPONSE_BOLETO_LINKS_HREF]; |
||
| 165 | } |
||
| 166 | } |
||
| 167 | |||
| 168 | $linkToPDF = $this->configBoleto->getFormattedLinkBoleto($relativeLinkToPDF); |
||
|
|
|||
| 169 | $payment->setAdditionalInformation( |
||
| 170 | self::PAYMENT_INFO_BOLETO_PDF_HREF, |
||
| 171 | $linkToPDF |
||
| 172 | ); |
||
| 173 | $transactionId = $payBoleto[self::RESPONSE_BOLETO_ID]; |
||
| 174 | $payment->setTransactionId($transactionId); |
||
| 175 | $payment->setIsTransactionPending(1); |
||
| 176 | $payment->setIsTransactionClosed(false); |
||
| 177 | $payment->setAuthorizationTransaction($transactionId); |
||
| 178 | $payment->addTransaction(Transaction::TYPE_AUTH); |
||
| 179 | |||
| 180 | $order = $payment->getOrder(); |
||
| 181 | $order->setState(\Magento\Sales\Model\Order::STATE_NEW); |
||
| 182 | $order->setStatus('pending'); |
||
| 183 | $comment = __('Awaiting payment of the boleto.'); |
||
| 184 | $order->addStatusHistoryComment($comment, $payment->getOrder()->getStatus()); |
||
| 185 | } |
||
| 187 |