ConfigProviderBoleto::getLogo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
rs 9.9
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;
10
11
use Magento\Checkout\Model\ConfigProviderInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Checkout\Model\ConfigProviderInterface 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
use Magento\Framework\Escaper;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Escaper 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...
13
use Magento\Framework\View\Asset\Source;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Asset\Source 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\Payment\Model\CcConfig;
0 ignored issues
show
Bug introduced by
The type Magento\Payment\Model\CcConfig 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\Quote\Api\Data\CartInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Api\Data\CartInterface 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
use Moip\Magento2\Gateway\Config\ConfigBoleto;
17
18
/**
19
 * Class ConfigProviderBoleto - Defines properties of the payment form..
20
 */
21
class ConfigProviderBoleto implements ConfigProviderInterface
22
{
23
    /*
24
     * @var CODE - Boleto
25
     */
26
    const CODE = 'moip_magento2_boleto';
27
28
    /**
29
     * @var Config
30
     */
31
    private $config;
32
33
    /**
34
     * @var CartInterface
35
     */
36
    private $cart;
37
38
    /**
39
     * @var array
40
     */
41
    private $icons = [];
0 ignored issues
show
introduced by
The private property $icons is not used, and could be removed.
Loading history...
42
43
    /**
44
     * @var CcConfig
45
     */
46
    protected $ccConfig;
47
48
    /**
49
     * @var \Magento\Framework\View\Asset\Source
50
     */
51
    protected $assetSource;
52
53
    /**
54
     * @param Config        $config
55
     * @param CartInterface $cart
56
     */
57
    public function __construct(
58
        ConfigBoleto $config,
59
        CartInterface $cart,
60
        CcConfig $ccConfig,
61
        Escaper $escaper,
62
        Source $assetSource
63
    ) {
64
        $this->config = $config;
65
        $this->cart = $cart;
66
        $this->escaper = $escaper;
0 ignored issues
show
Bug Best Practice introduced by
The property escaper does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
67
        $this->ccConfig = $ccConfig;
68
        $this->assetSource = $assetSource;
69
    }
70
71
    /**
72
     * Retrieve assoc array of checkout configuration.
73
     *
74
     * @return array
75
     */
76
    public function getConfig()
77
    {
78
        $storeId = $this->cart->getStoreId();
79
80
        return [
81
            'payment' => [
82
                ConfigBoleto::METHOD => [
83
                    'isActive'             => $this->config->isActive($storeId),
84
                    'title'                => $this->config->getTitle($storeId),
85
                    'name_capture'         => $this->config->getUseNameCapture($storeId),
86
                    'tax_document_capture' => $this->config->getUseTaxDocumentCapture($storeId),
87
                    'expiration'           => nl2br(
88
                        $this->escaper->escapeHtml(
89
                            $this->config->getExpirationFormat($storeId)
90
                        )
91
                    ),
92
                    'instruction_checkout' => nl2br(
93
                        $this->escaper->escapeHtml(
94
                            $this->config->getInstructionCheckout($storeId)
95
                        )
96
                    ),
97
                    'logo'                 => $this->getLogo(),
98
                ],
99
            ],
100
        ];
101
    }
102
103
    /**
104
     * Get icons for available payment methods.
105
     *
106
     * @return array
107
     */
108
    public function getLogo()
109
    {
110
        $logo = [];
111
        $asset = $this->ccConfig->createAsset('Moip_Magento2::images/boleto/moipboleto.svg');
112
        $placeholder = $this->assetSource->findSource($asset);
113
        if ($placeholder) {
114
            list($width, $height) = getimagesizefromstring($asset->getSourceFile());
115
            $logo = [
116
                'url'    => $asset->getUrl(),
117
                'width'  => $width,
118
                'height' => $height,
119
                'title'  => __('Moip'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

119
                'title'  => /** @scrutinizer ignore-call */ __('Moip'),
Loading history...
120
            ];
121
        }
122
123
        return $logo;
124
    }
125
}
126