Passed
Branch [email protected] (3810d0)
by Bruno
11:09
created

DynamicMccDataRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A build() 0 10 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\SubjectReader;
13
use InvalidArgumentException;
14
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
15
use Magento\Payment\Gateway\Request\BuilderInterface;
16
17
/**
18
 * Class Dynamic Mcc Data Request - Dynamic Mcc structure.
19
 */
20
class DynamicMccDataRequest implements BuilderInterface
21
{
22
    /**
23
     * Dynamic Mcc  block name.
24
     */
25
    public const DYNAMIC_MCC = 'dynamic_mcc';
26
27
    /**
28
     * @var SubjectReader
29
     */
30
    protected $subjectReader;
31
32
    /**
33
     * @var Config
34
     */
35
    protected $config;
36
37
    /**
38
     * @param SubjectReader $subjectReader
39
     * @param Config        $config
40
     */
41
    public function __construct(
42
        SubjectReader $subjectReader,
43
        Config $config
44
    ) {
45
        $this->subjectReader = $subjectReader;
46
        $this->config = $config;
47
    }
48
49
    /**
50
     * Build.
51
     *
52
     * @param array $buildSubject
53
     */
54
    public function build(array $buildSubject): array
55
    {
56
        if (!isset($buildSubject['payment'])
57
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
58
        ) {
59
            throw new InvalidArgumentException('Payment data object should be provided');
60
        }
61
62
        return [
63
            self::DYNAMIC_MCC => $this->config->getMerchantGatewayDynamicMcc(),
64
        ];
65
    }
66
}
67