StoreIdDataRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
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 Store Id Data Request - Store Id structure.
19
 */
20
class StoreIdDataRequest implements BuilderInterface
21
{
22
    /**
23
     * Store Id block name.
24
     */
25
    public const STORE_ID = 'store_id';
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
        $paymentDO = $buildSubject['payment'];
62
        $order = $paymentDO->getOrder();
63
        $storeId = $order->getStoreId();
64
65
        return [
66
            self::STORE_ID  => $storeId ?: 0,
67
        ];
68
    }
69
}
70