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

ConfigProvider::getIcons()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 26

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
rs 9.1928
c 0
b 0
f 0
cc 5
nc 5
nop 0
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\Model\Ui\Vault;
10
11
use Magento\Checkout\Model\ConfigProviderInterface;
12
use Magento\Framework\Exception\InputException;
13
use Magento\Framework\Exception\NoSuchEntityException;
14
use Magento\Framework\View\Asset\Source;
15
use Magento\Payment\Model\CcConfig;
16
use Magento\Quote\Api\Data\CartInterface;
17
use Moip\Magento2\Gateway\Config\ConfigCc;
18
use Moip\Magento2\Gateway\Config\ConfigCcVault;
19
20
class ConfigProvider implements ConfigProviderInterface
21
{
22
    const CODE = 'moip_magento2_cc_vault';
23
    /**
24
     * @var Config
25
     */
26
    private $configCcVault;
27
28
    /**
29
     * @var CartInterface
30
     */
31
    private $cart;
32
33
    /**
34
     * @var array
35
     */
36
    private $icons = [];
37
38
    /**
39
     * @var CcConfig
40
     */
41
    protected $ccConfig;
42
43
    /**
44
     * @var CcConfig
45
     */
46
    protected $configCc;
47
48
    /**
49
     * @var \Magento\Framework\View\Asset\Source
50
     */
51
    protected $assetSource;
52
53
    /**
54
     * ConfigProvider constructor.
55
     *
56
     * @param Config $config
0 ignored issues
show
Documentation introduced by
There is no parameter named $config. Did you maybe mean $configCc?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
57
     */
58 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        CartInterface $cart,
60
        ConfigCc $configCc,
61
        ConfigCcVault $configCcVault,
62
        CcConfig $ccConfig,
63
        Source $assetSource
64
    ) {
65
        $this->cart = $cart;
66
        $this->configCc = $configCc;
67
        $this->assetSource = $assetSource;
68
        $this->ccConfig = $ccConfig;
69
        $this->configCcVault = $configCcVault;
70
    }
71
72
    /**
73
     * Retrieve assoc array of checkout configuration.
74
     *
75
     * @throws InputException
76
     * @throws NoSuchEntityException
77
     *
78
     * @return array
79
     */
80
    public function getConfig()
81
    {
82
        $storeId = $this->cart->getStoreId();
83
84
        return [
85
            'payment' => [
86
                self::CODE => [
87
                    'useCvv' => $this->configCcVault->useCvv($storeId),
88
                    'icons'  => $this->getIcons(),
89
                ],
90
            ],
91
        ];
92
    }
93
94
    /**
95
     * Get icons for available payment methods.
96
     *
97
     * @return array
98
     */
99 View Code Duplication
    public function getIcons()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        if (!empty($this->icons)) {
102
            return $this->icons;
103
        }
104
        $storeId = $this->cart->getStoreId();
105
        $ccTypes = $this->configCc->getCcAvailableTypes($storeId);
106
        $types = explode(',', $ccTypes);
107
        foreach ($types as $code => $label) {
108
            if (!array_key_exists($code, $this->icons)) {
109
                $asset = $this->ccConfig->createAsset('Moip_Magento2::images/cc/'.strtolower($label).'.svg');
110
                $placeholder = $this->assetSource->findSource($asset);
111
                if ($placeholder) {
112
                    list($width, $height) = getimagesizefromstring($asset->getSourceFile());
113
                    $this->icons[$label] = [
114
                        'url'    => $asset->getUrl(),
115
                        'width'  => $width,
116
                        'height' => $height,
117
                        'title'  => __($label),
118
                    ];
119
                }
120
            }
121
        }
122
123
        return $this->icons;
124
    }
125
}
126