Issues (139)

Model/Ui/ConfigProviderBoleto.php (1 issue)

Labels
Severity
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 Getnet\PaymentMagento\Gateway\Config\ConfigBoleto;
12
use Magento\Checkout\Model\ConfigProviderInterface;
13
use Magento\Framework\Escaper;
14
use Magento\Framework\View\Asset\Source;
15
use Magento\Payment\Model\CcConfig;
16
use Magento\Quote\Api\Data\CartInterface;
17
18
/**
19
 * Class ConfigProviderBoleto - Defines properties of the payment form..
20
 */
21
class ConfigProviderBoleto implements ConfigProviderInterface
22
{
23
    /*
24
     * @const string
25
     */
26
    public const CODE = 'getnet_paymentmagento_boleto';
27
28
    /**
29
     * @var ConfigBoleto
30
     */
31
    private $config;
32
33
    /**
34
     * @var CartInterface
35
     */
36
    private $cart;
37
38
    /**
39
     * @var CcConfig
40
     */
41
    protected $ccConfig;
42
43
    /**
44
     * @var Escaper
45
     */
46
    protected $escaper;
47
48
    /**
49
     * @var Source
50
     */
51
    protected $assetSource;
52
53
    /**
54
     * @param ConfigBoleto  $config
55
     * @param CartInterface $cart
56
     * @param CcConfig      $ccConfig
57
     * @param Escaper       $escaper
58
     * @param Source        $assetSource
59
     */
60
    public function __construct(
61
        ConfigBoleto $config,
62
        CartInterface $cart,
63
        CcConfig $ccConfig,
64
        Escaper $escaper,
65
        Source $assetSource
66
    ) {
67
        $this->config = $config;
68
        $this->cart = $cart;
69
        $this->escaper = $escaper;
70
        $this->ccConfig = $ccConfig;
71
        $this->assetSource = $assetSource;
72
    }
73
74
    /**
75
     * Retrieve assoc array of checkout configuration.
76
     *
77
     * @return array
78
     */
79
    public function getConfig()
80
    {
81
        $storeId = $this->cart->getStoreId();
82
83
        return [
84
            'payment' => [
85
                ConfigBoleto::METHOD => [
86
                    'isActive'             => $this->config->isActive($storeId),
87
                    'title'                => $this->config->getTitle($storeId),
88
                    'name_capture'         => $this->config->hasUseNameCapture($storeId),
89
                    'tax_document_capture' => $this->config->hasUseTaxDocumentCapture($storeId),
90
                    'expiration'           => nl2br(
91
                        $this->escaper->escapeHtml(
0 ignored issues
show
It seems like $this->escaper->escapeHt...rationFormat($storeId)) can also be of type array; however, parameter $string of nl2br() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

91
                        /** @scrutinizer ignore-type */ $this->escaper->escapeHtml(
Loading history...
92
                            $this->config->getExpirationFormat($storeId)
93
                        )
94
                    ),
95
                    'instruction_checkout' => nl2br(
96
                        $this->escaper->escapeHtml(
97
                            $this->config->getInstructionCheckout($storeId)
98
                        )
99
                    ),
100
                    'logo'                 => $this->getLogo(),
101
                ],
102
            ],
103
        ];
104
    }
105
106
    /**
107
     * Get icons for available payment methods.
108
     *
109
     * @return array
110
     */
111
    public function getLogo()
112
    {
113
        $logo = [];
114
        $asset = $this->ccConfig->createAsset('Getnet_PaymentMagento::images/boleto/logo.svg');
115
        $placeholder = $this->assetSource->findSource($asset);
116
        if ($placeholder) {
117
            list($width, $height) = getimagesizefromstring($asset->getSourceFile());
118
            $logo = [
119
                'url'    => $asset->getUrl(),
120
                'width'  => $width,
121
                'height' => $height,
122
                'title'  => __('Getnet'),
123
            ];
124
        }
125
126
        return $logo;
127
    }
128
}
129