Passed
Push — main ( 6b22cc...840532 )
by Bruno
09:36 queued 04:25
created

ConfigProviderGetpay::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 9.9332
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\ConfigGetpay;
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 ConfigProviderGetpay - Defines properties of the payment form..
20
 */
21
class ConfigProviderGetpay implements ConfigProviderInterface
22
{
23
    /*
24
     * @const string
25
     */
26
    public const CODE = 'getnet_paymentmagento_getpay';
27
28
    /**
29
     * @var ConfigGetpay
30
     */
31
    protected $config;
32
33
    /**
34
     * @var CartInterface
35
     */
36
    protected $cart;
37
38
    /**
39
     * @var CcConfig
40
     */
41
    protected $ccConfig;
42
43
    /**
44
     * @var Source
45
     */
46
    protected $assetSource;
47
48
    /**
49
     * @param ConfigGetpay  $config
50
     * @param CartInterface $cart
51
     * @param CcConfig      $ccConfig
52
     * @param Escaper       $escaper
53
     * @param Source        $assetSource
54
     */
55
    public function __construct(
56
        ConfigGetpay $config,
57
        CartInterface $cart,
58
        CcConfig $ccConfig,
59
        Escaper $escaper,
60
        Source $assetSource
61
    ) {
62
        $this->config = $config;
63
        $this->cart = $cart;
64
        $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...
65
        $this->ccConfig = $ccConfig;
66
        $this->assetSource = $assetSource;
67
    }
68
69
    /**
70
     * Retrieve assoc array of checkout configuration.
71
     *
72
     * @return array
73
     */
74
    public function getConfig()
75
    {
76
        $storeId = $this->cart->getStoreId();
77
78
        return [
79
            'payment' => [
80
                self::CODE => [
81
                    'isActive'             => $this->config->isActive($storeId),
82
                    'title'                => $this->config->getTitle($storeId),
83
                    'instruction_checkout' => nl2br(
84
                        $this->escaper->escapeHtml(
0 ignored issues
show
Bug introduced by
It seems like $this->escaper->escapeHt...tionCheckout($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

84
                        /** @scrutinizer ignore-type */ $this->escaper->escapeHtml(
Loading history...
85
                            $this->config->getInstructionCheckout($storeId)
86
                        )
87
                    ),
88
                    'logo'                 => $this->getLogo(),
89
                ],
90
            ],
91
        ];
92
    }
93
94
    /**
95
     * Get icons for available payment methods.
96
     *
97
     * @return array
98
     */
99
    public function getLogo()
100
    {
101
        $logo = [];
102
        $asset = $this->ccConfig->createAsset('Getnet_PaymentMagento::images/pix/logo.svg');
103
        $placeholder = $this->assetSource->findSource($asset);
104
        if ($placeholder) {
105
            list($width, $height) = getimagesizefromstring($asset->getSourceFile());
106
            $logo = [
107
                'url'    => $asset->getUrl(),
108
                'width'  => $width,
109
                'height' => $height,
110
                'title'  => __('Getnet'),
111
            ];
112
        }
113
114
        return $logo;
115
    }
116
}
117