BoletoPaymentDataRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 91
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 14 3
A getDataPaymetBoleto() 0 10 1
A __construct() 0 8 1
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\ConfigBoleto;
13
use Getnet\PaymentMagento\Gateway\Data\Order\OrderAdapterFactory;
0 ignored issues
show
Bug introduced by
The type Getnet\PaymentMagento\Ga...der\OrderAdapterFactory 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...
14
use Getnet\PaymentMagento\Gateway\SubjectReader;
15
use InvalidArgumentException;
16
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
17
use Magento\Payment\Gateway\Request\BuilderInterface;
18
19
/**
20
 * Class Boleto Payment Data Request - Payment data structure for boleto.
21
 */
22
class BoletoPaymentDataRequest implements BuilderInterface
23
{
24
    /**
25
     * Method - Block Name.
26
     */
27
    public const METHOD = 'boleto';
28
29
    /**
30
     * Installment count - Number of payment installments.
31
     */
32
    public const DOCUMENT_NUMBER = 'document_number';
33
34
    /**
35
     * Boleto expiration date - Due date.
36
     */
37
    public const BOLETO_EXPIRATION_DATE = 'expiration_date';
38
39
    /**
40
     * Boleto Instruction - Block name.
41
     */
42
    public const BOLETO_INSTRUCTION = 'instructions';
43
44
    /**
45
     * @var SubjectReader
46
     */
47
    protected $subjectReader;
48
49
    /**
50
     * @var Config
51
     */
52
    protected $config;
53
54
    /**
55
     * @var ConfigBoleto
56
     */
57
    protected $configBoleto;
58
59
    /**
60
     * @param SubjectReader $subjectReader
61
     * @param Config        $config
62
     * @param ConfigBoleto  $configBoleto
63
     */
64
    public function __construct(
65
        SubjectReader $subjectReader,
66
        Config $config,
67
        ConfigBoleto $configBoleto
68
    ) {
69
        $this->subjectReader = $subjectReader;
70
        $this->config = $config;
71
        $this->configBoleto = $configBoleto;
72
    }
73
74
    /**
75
     * Build.
76
     *
77
     * @param array $buildSubject
78
     */
79
    public function build(array $buildSubject)
80
    {
81
        if (!isset($buildSubject['payment'])
82
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
83
        ) {
84
            throw new InvalidArgumentException('Payment data object should be provided');
85
        }
86
87
        $paymentDO = $buildSubject['payment'];
88
        $order = $paymentDO->getOrder();
89
        $storeId = $order->getStoreId();
90
        $result = $this->getDataPaymetBoleto($order, $storeId);
91
92
        return $result;
93
    }
94
95
    /**
96
     * Data for Boleto.
97
     *
98
     * @param OrderAdapterFactory $order
99
     * @param int                 $storeId
100
     *
101
     * @return array
102
     */
103
    public function getDataPaymetBoleto($order, $storeId)
104
    {
105
        $instruction = [];
106
        $instruction[self::METHOD] = [
107
            self::DOCUMENT_NUMBER          => $order->getOrderIncrementId(),
108
            self::BOLETO_INSTRUCTION       => $this->configBoleto->getInstructionLine($storeId),
109
            self::BOLETO_EXPIRATION_DATE   => $this->configBoleto->getExpiration($storeId),
110
        ];
111
112
        return $instruction;
113
    }
114
}
115