TokenUiComponentProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getComponentForToken() 0 16 1
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\Model\Ui;
10
11
use Magento\Framework\Serialize\Serializer\Json;
12
use Magento\Vault\Api\Data\PaymentTokenInterface;
13
use Magento\Vault\Model\Ui\TokenUiComponentInterface;
14
use Magento\Vault\Model\Ui\TokenUiComponentInterfaceFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Vault\Model\Ui\T...mponentInterfaceFactory 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\Model\Ui\TokenUiComponentProviderInterface;
16
17
/**
18
 * Class TokenUiComponentProvider - Defines properties of the payment form.
19
 */
20
class TokenUiComponentProvider implements TokenUiComponentProviderInterface
21
{
22
    /**
23
     * @var TokenUiComponentInterfaceFactory
24
     */
25
    private $componentFactory;
26
27
    /**
28
     * @var Json
29
     */
30
    protected $json;
31
32
    /**
33
     * TokenUiComponentProvider constructor.
34
     *
35
     * @param TokenUiComponentInterfaceFactory $componentFactory
36
     * @param Json                             $json
37
     */
38
    public function __construct(
39
        TokenUiComponentInterfaceFactory $componentFactory,
40
        Json $json
41
    ) {
42
        $this->componentFactory = $componentFactory;
43
        $this->json = $json;
44
    }
45
46
    /**
47
     * Get UI component for token.
48
     *
49
     * @param PaymentTokenInterface $paymentToken
50
     *
51
     * @return TokenUiComponentInterface
52
     */
53
    public function getComponentForToken(PaymentTokenInterface $paymentToken)
54
    {
55
        $jsonDetails = $this->json->unserialize($paymentToken->getTokenDetails());
56
        $component = $this->componentFactory->create(
57
            [
58
                'config' => [
59
                    // phpcs:ignore Generic.Files.LineLength
60
                    'code'                                                   => ConfigProviderBase::METHOD_CODE_CC_VAULT,
61
                    TokenUiComponentProviderInterface::COMPONENT_DETAILS     => $jsonDetails,
62
                    TokenUiComponentProviderInterface::COMPONENT_PUBLIC_HASH => $paymentToken->getPublicHash(),
63
                ],
64
                'name' => 'Getnet_PaymentMagento/js/view/payment/method-renderer/vault',
65
            ]
66
        );
67
68
        return $component;
69
    }
70
}
71