DeviceDataRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * Copyright © Wirecard Brasil. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See COPYING.txt for license details.
7
 */
8
9
namespace Moip\Magento2\Gateway\Request;
10
11
use Magento\Framework\HTTP\Header as HeaderClient;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\HTTP\Header 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...
12
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\HTTP\P...vironment\RemoteAddress 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...
13
use Magento\Payment\Gateway\Request\BuilderInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\Request\BuilderInterface 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 Moip\Magento2\Gateway\SubjectReader;
15
16
/**
17
 * Class DeviceDataRequest - User Device Data Structure.
18
 */
19
class DeviceDataRequest implements BuilderInterface
20
{
21
    /**
22
     * Device data customer.
23
     */
24
    const DEVICE_DATA = 'device';
25
26
    /**
27
     * RemoteIP data.
28
     */
29
    const REMOTE_IP = 'ip';
30
31
    /**
32
     * RemoteUserAgent data.
33
     */
34
    const REMOTE_USER_AGENT = 'userAgent';
35
36
    /**
37
     * @var SubjectReader
38
     */
39
    private $subjectReader;
40
41
    /**
42
     * @var remoteAddress
43
     */
44
    private $remoteAddress;
45
46
    /**
47
     * @var headerClient
48
     */
49
    private $headerClient;
50
51
    /**
52
     * @param RemoteAddress $remoteAddress
53
     * @param HeaderClient  $headerClient
54
     * @param SubjectReader $subjectReader
55
     */
56
    public function __construct(
57
        RemoteAddress $remoteAddress,
58
        HeaderClient $headerClient,
59
        SubjectReader $subjectReader
60
    ) {
61
        $this->remoteAddress = $remoteAddress;
62
        $this->headerClient = $headerClient;
63
        $this->subjectReader = $subjectReader;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function build(array $buildSubject)
70
    {
71
        $paymentDO = $this->subjectReader->readPayment($buildSubject);
72
73
        $result = [];
74
        $ipCustomer = $this->remoteAddress->getRemoteAddress();
75
        if (empty($ipCustomer)) {
76
            $payment = $paymentDO->getPayment();
77
            $order = $payment->getOrder();
78
            $ipCustomer = $order->getXForwardedFor();
79
        }
80
        $result[PaymentDataRequest::PAYMENT_INSTRUMENT][self::DEVICE_DATA] = [
81
            self::REMOTE_IP         => $ipCustomer,
82
            self::REMOTE_USER_AGENT => $this->headerClient->getHttpUserAgent(),
83
        ];
84
85
        $paymentInfo = $paymentDO->getPayment();
86
87
        $paymentInfo->setAdditionalInformation(
88
            self::DEVICE_DATA,
89
            $result[PaymentDataRequest::PAYMENT_INSTRUMENT][self::DEVICE_DATA]
90
        );
91
92
        return $result;
93
    }
94
}
95