OrderDataPixRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 17 3
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\PaymentMagento\Gateway\Request;
10
11
use Getnet\PaymentMagento\Gateway\SubjectReader;
12
use InvalidArgumentException;
13
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
14
use Magento\Payment\Gateway\Request\BuilderInterface;
15
16
/**
17
 * Class Order Data Pix Request - Payment amount structure.
18
 */
19
class OrderDataPixRequest implements BuilderInterface
20
{
21
    /**
22
     * Order Id Block Name.
23
     */
24
    public const ORDER_ID = 'order_id';
25
26
    /**
27
     * @var SubjectReader
28
     */
29
    protected $subjectReader;
30
31
    /**
32
     * @param SubjectReader $subjectReader
33
     */
34
    public function __construct(
35
        SubjectReader $subjectReader
36
    ) {
37
        $this->subjectReader = $subjectReader;
38
    }
39
40
    /**
41
     * Build.
42
     *
43
     * @param array $buildSubject
44
     */
45
    public function build(array $buildSubject)
46
    {
47
        if (!isset($buildSubject['payment'])
48
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
49
        ) {
50
            throw new InvalidArgumentException('Payment data object should be provided');
51
        }
52
53
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
54
55
        $result = [];
56
57
        $order = $paymentDO->getOrder();
58
59
        $result[self::ORDER_ID] = $order->getOrderIncrementId();
60
61
        return $result;
62
    }
63
}
64