FraudHandler::handle()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 24
rs 9.5555
1
<?php
2
/**
3
 * Copyright © 2016 Magento. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
namespace Pagantis\Pagantis\Gateway\Response;
7
8
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
9
use Magento\Payment\Gateway\Response\HandlerInterface;
10
use Magento\Sales\Model\Order\Payment;
11
12
class FraudHandler implements HandlerInterface
13
{
14
    const FRAUD_MSG_LIST = 'FRAUD_MSG_LIST';
15
16
    /**
17
     * Handles fraud messages
18
     *
19
     * @param array $handlingSubject
20
     * @param array $response
21
     * @return void
22
     */
23
    public function handle(array $handlingSubject, array $response)
24
    {
25
        if (!isset($response[self::FRAUD_MSG_LIST]) || !is_array($response[self::FRAUD_MSG_LIST])) {
26
            return;
27
        }
28
29
        if (!isset($handlingSubject['payment'])
30
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
31
        ) {
32
            throw new \InvalidArgumentException('Payment data object should be provided');
33
        }
34
35
        /** @var PaymentDataObjectInterface $paymentDO */
36
        $paymentDO = $handlingSubject['payment'];
37
        $payment = $paymentDO->getPayment();
38
39
        $payment->setAdditionalInformation(
40
            self::FRAUD_MSG_LIST,
41
            (array)$response[self::FRAUD_MSG_LIST]
0 ignored issues
show
Bug introduced by
(array)$response[self::FRAUD_MSG_LIST] of type array is incompatible with the type null|string expected by parameter $value of Magento\Payment\Model\In...AdditionalInformation(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
            /** @scrutinizer ignore-type */ (array)$response[self::FRAUD_MSG_LIST]
Loading history...
42
        );
43
44
        /** @var $payment Payment */
45
        $payment->setIsTransactionPending(true);
46
        $payment->setIsFraudDetected(true);
47
    }
48
}
49