PaymentToken   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A aroundSaveTokenWithPaymentLink() 0 25 3
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
declare(strict_types=1);
10
11
namespace Moip\Magento2\Plugin;
12
13
use Magento\Sales\Api\Data\OrderPaymentInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Sales\Api\Data\OrderPaymentInterface 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 Magento\Vault\Api\Data\PaymentTokenInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Vault\Api\Data\PaymentTokenInterface 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...
15
use Magento\Vault\Api\PaymentTokenManagementInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Vault\Api\PaymentTokenManagementInterface 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...
16
17
/**
18
 * Class PaymentTokenManagementInterface - Fixed Issue #84.
19
 */
20
class PaymentToken
21
{
22
    public function aroundSaveTokenWithPaymentLink(
23
        PaymentTokenManagementInterface $paymentTokenManagement,
24
        callable $proceed,
25
        PaymentTokenInterface $token,
26
        OrderPaymentInterface $payment
27
    ): bool {
28
        $order = $payment->getOrder();
29
30
        if ($order->getCustomerIsGuest()) {
31
            return $proceed($token, $payment);
32
        }
33
34
        $existingToken = $paymentTokenManagement->getByGatewayToken(
35
            $token->getGatewayToken(),
36
            $payment->getMethodInstance()->getCode(),
37
            $order->getCustomerId()
38
        );
39
40
        if ($existingToken === null) {
41
            return $proceed($token, $payment);
42
        }
43
44
        $existingToken->addData($token->getData());
45
46
        return $proceed($existingToken, $payment);
47
    }
48
}
49