ExtOrdIdHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 15
rs 10
1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Gateway\Response;
10
11
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\...mentDataObjectInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Payment\Gateway\Response\HandlerInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\Response\HandlerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
/**
15
 * Class ExtOrdIdHandler - Handles reading responses for creating order.
16
 */
17
class ExtOrdIdHandler implements HandlerInterface
18
{
19
    /**
20
     * @const EXT ORD ID
21
     */
22
    const EXTERNAL_ORDER_ID = 'EXT_ORD_ID';
23
24
    /**
25
     * Handles.
26
     *
27
     * @param array $handlingSubject
28
     * @param array $response
29
     */
30
    public function handle(array $handlingSubject, array $response)
31
    {
32
        if (!isset($handlingSubject['payment'])
33
            || !$handlingSubject['payment'] instanceof PaymentDataObjectInterface
34
        ) {
35
            throw new \InvalidArgumentException('Payment data object should be provided');
36
        }
37
38
        $paymentDO = $handlingSubject['payment'];
39
40
        $payment = $paymentDO->getPayment();
41
42
        $order = $payment->getOrder();
43
44
        $order->setExtOrderId($response[self::EXTERNAL_ORDER_ID]);
45
    }
46
}
47