Passed
Push — master ( 2fd05c...9d8025 )
by Bruno
02:00
created

VaultDataBuilder::build()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 4
nop 1
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;
10
use Magento\Payment\Gateway\Request\BuilderInterface;
11
use Magento\Vault\Model\Ui\VaultConfigProvider;
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
0 ignored issues
show
Bug introduced by
The class Magento\Payment\Gateway\...mentDataObjectInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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
Bug introduced by
The variable $data seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
41
                $result[self::OPTIONS] = [
42
                    self::STORE_IN_VAULT_ON_SUCCESS => true,
43
                ];
44
            }
45
        }
46
47
        return $result;
48
    }
49
}
50