VaultDataBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 19 5
1
<?php
2
/**
3
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
7
namespace Moip\Magento2\Gateway\Request;
8
9
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Gateway\...mentDataObjectInterface 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...
10
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...
11
use Magento\Vault\Model\Ui\VaultConfigProvider;
0 ignored issues
show
Bug introduced by
The type Magento\Vault\Model\Ui\VaultConfigProvider 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
13
class VaultDataBuilder implements BuilderInterface
14
{
15
    /**
16
     * Additional options in request to gateway.
17
     */
18
    const OPTIONS = 'options';
19
20
    /**
21
     * The option that determines whether the payment method associated with
22
     * the successful transaction should be stored in the Vault.
23
     */
24
    const STORE_IN_VAULT_ON_SUCCESS = 'storeInVaultOnSuccess';
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function build(array $buildSubject): array
30
    {
31
        if (!isset($buildSubject['payment'])
32
            || !$buildSubject['payment'] instanceof PaymentDataObjectInterface
33
        ) {
34
            throw new \InvalidArgumentException('Payment data object should be provided');
35
        }
36
        $result = [];
37
        $paymentDO = $buildSubject['payment'];
38
        $payment = $paymentDO->getPayment();
39
        if ($payment->getMethod() === 'moip_magento2_cc') {
40
            if (!empty($data[$payment->getAdditionalInformation(VaultConfigProvider::IS_ACTIVE_CODE)])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to never exist and therefore empty should always be true.
Loading history...
41
                $result[self::OPTIONS] = [
42
                    self::STORE_IN_VAULT_ON_SUCCESS => true,
43
                ];
44
            }
45
        }
46
47
        return $result;
48
    }
49
}
50