CurrencyDataRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 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\Config\Config;
12
use Getnet\PaymentMagento\Gateway\Config\ConfigCc;
13
use Getnet\PaymentMagento\Gateway\SubjectReader;
14
use InvalidArgumentException;
15
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
16
use Magento\Payment\Gateway\Request\BuilderInterface;
17
18
/**
19
 * Class Currency Data Request - Payment Currency structure.
20
 */
21
class CurrencyDataRequest implements BuilderInterface
22
{
23
    /**
24
     * Currency block name.
25
     */
26
    public const CURRENCY = 'currency';
27
28
    /**
29
     * @var SubjectReader
30
     */
31
    protected $subjectReader;
32
33
    /**
34
     * @var Config
35
     */
36
    protected $config;
37
38
    /**
39
     * @var ConfigCc
40
     */
41
    protected $configCc;
42
43
    /**
44
     * @param SubjectReader $subjectReader
45
     * @param Config        $config
46
     * @param ConfigCc      $configCc
47
     */
48
    public function __construct(
49
        SubjectReader $subjectReader,
50
        Config $config,
51
        ConfigCc $configCc
52
    ) {
53
        $this->subjectReader = $subjectReader;
54
        $this->config = $config;
55
        $this->configCc = $configCc;
56
    }
57
58
    /**
59
     * Build.
60
     *
61
     * @param array $buildSubject
62
     */
63
    public function build(array $buildSubject)
64
    {
65
        if (!isset($buildSubject['payment'])
66
        || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
67
        ) {
68
            throw new InvalidArgumentException('Payment data object should be provided');
69
        }
70
71
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
72
73
        $result = [];
74
75
        $order = $paymentDO->getOrder();
76
77
        $result[self::CURRENCY] = $order->getCurrencyCode();
78
79
        return $result;
80
    }
81
}
82