PaymentGroup   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 171
Duplicated Lines 0 %

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A _isPaymentEnabled() 0 16 5
A _getFrontendClass() 0 5 2
A _isCollapseState() 0 3 1
A _getHeaderTitleHtml() 0 32 2
A _getExtraJs() 0 22 1
A _getHeaderCommentHtml() 0 3 1
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\Block\Adminhtml\System\Config;
10
11
use Magento\Framework\App\ObjectManager;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\ObjectManager 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\View\Helper\SecureHtmlRenderer;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Helper\SecureHtmlRenderer 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
14
/**
15
 * Class PaymentGroup - Fieldset renderer for moip.
16
 */
17
class PaymentGroup extends \Magento\Config\Block\System\Config\Form\Fieldset
0 ignored issues
show
Bug introduced by
The type Magento\Config\Block\System\Config\Form\Fieldset 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...
18
{
19
    /**
20
     * @var \Magento\Config\Model\Config
0 ignored issues
show
Bug introduced by
The type Magento\Config\Model\Config 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...
21
     */
22
    protected $_backendConfig;
23
24
    /**
25
     * @var SecureHtmlRenderer
26
     */
27
    private $secureRenderer;
28
29
    /**
30
     * @param \Magento\Backend\Block\Context      $context
31
     * @param \Magento\Backend\Model\Auth\Session $authSession
32
     * @param \Magento\Framework\View\Helper\Js   $jsHelper
33
     * @param \Magento\Config\Model\Config        $backendConfig
34
     * @param array                               $data
35
     * @param SecureHtmlRenderer|null             $secureRenderer
36
     */
37
    public function __construct(
38
        \Magento\Backend\Block\Context $context,
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Block\Context 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...
39
        \Magento\Backend\Model\Auth\Session $authSession,
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Model\Auth\Session 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...
40
        \Magento\Framework\View\Helper\Js $jsHelper,
0 ignored issues
show
Bug introduced by
The type Magento\Framework\View\Helper\Js 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...
41
        \Magento\Config\Model\Config $backendConfig,
42
        SecureHtmlRenderer $secureRenderer,
43
        array $data = []
44
    ) {
45
        $this->_backendConfig = $backendConfig;
46
        $secureRenderer = $secureRenderer ?? ObjectManager::getInstance()->get(SecureHtmlRenderer::class);
47
        parent::__construct($context, $authSession, $jsHelper, $data, $secureRenderer);
48
        $this->secureRenderer = $secureRenderer;
49
    }
50
51
    /**
52
     * Add custom css class.
53
     *
54
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Data\F...Element\AbstractElement 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...
55
     *
56
     * @return string
57
     */
58
    protected function _getFrontendClass($element)
59
    {
60
        $enabledString = $this->_isPaymentEnabled($element) ? ' enabled' : '';
61
62
        return parent::_getFrontendClass($element).' with-button'.$enabledString;
63
    }
64
65
    /**
66
     * Check whether current payment method is enabled.
67
     *
68
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
69
     *
70
     * @return bool
71
     */
72
    protected function _isPaymentEnabled($element)
73
    {
74
        $groupConfig = $element->getGroup();
75
        $activityPaths = isset($groupConfig['activity_path']) ? $groupConfig['activity_path'] : [];
76
77
        if (!is_array($activityPaths)) {
78
            $activityPaths = [$activityPaths];
79
        }
80
81
        $isPaymentEnabled = false;
82
        foreach ($activityPaths as $activityPath) {
83
            $isPaymentEnabled = $isPaymentEnabled
84
                || (bool) (string) $this->_backendConfig->getConfigDataValue($activityPath);
85
        }
86
87
        return $isPaymentEnabled;
88
    }
89
90
    /**
91
     * Return header title part of html for payment solution.
92
     *
93
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
94
     *
95
     * @return string
96
     * @SuppressWarnings(PHPMD.NPathComplexity)
97
     */
98
    protected function _getHeaderTitleHtml($element)
99
    {
100
        $html = '<div class="config-heading" >';
101
102
        $groupConfig = $element->getGroup();
0 ignored issues
show
Unused Code introduced by
The assignment to $groupConfig is dead and can be removed.
Loading history...
103
104
        $htmlId = $element->getHtmlId();
105
        $html .= '<div class="button-container"><button type="button"'.
106
            ' class="button action-configure'.
107
            '" id="'.$htmlId.'-head" >'.
108
            '<span class="state-closed">'.__(
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

108
            '<span class="state-closed">'./** @scrutinizer ignore-call */ __(
Loading history...
109
                'Configure'
110
            ).'</span><span class="state-opened">'.__(
111
                'Close'
112
            ).'</span></button>';
113
114
        $html .= /* @noEscape */ $this->secureRenderer->renderEventListenerAsTag(
115
            'onclick',
116
            "moipToggleSolution.call(this, '".$htmlId."', '".$this->getUrl('adminhtml/*/state').
117
            "');event.preventDefault();",
118
            'button#'.$htmlId.'-head'
119
        );
120
        $html .= '</div>';
121
        $html .= '<div class="heading"><strong>'.$element->getLegend().'</strong>';
122
123
        if ($element->getComment()) {
124
            $html .= '<span class="heading-intro">'.$element->getComment().'</span>';
125
        }
126
        $html .= '<div class="config-alt"></div>';
127
        $html .= '</div></div>';
128
129
        return $html;
130
    }
131
132
    /**
133
     * Return header comment part of html for payment solution.
134
     *
135
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
136
     *
137
     * @return string
138
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
139
     */
140
    protected function _getHeaderCommentHtml($element)
141
    {
142
        return '';
143
    }
144
145
    /**
146
     * Get collapsed state on-load.
147
     *
148
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
149
     *
150
     * @return false
151
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
152
     */
153
    protected function _isCollapseState($element)
154
    {
155
        return false;
156
    }
157
158
    /**
159
     * Return extra Js.
160
     *
161
     * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
162
     *
163
     * @return string
164
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
165
     */
166
    protected function _getExtraJs($element)
167
    {
168
        $script = "require(['jquery', 'prototype'], function(jQuery){
169
            window.moipToggleSolution = function (id, url) {
170
                var doScroll = false;
171
                Fieldset.toggleCollapse(id, url);
172
                if ($(this).hasClassName(\"open\")) {
173
                    \$$(\".with-button button.button\").each(function(anotherButton) {
174
                        if (anotherButton != this && $(anotherButton).hasClassName(\"open\")) {
175
                            $(anotherButton).click();
176
                            doScroll = true;
177
                        }
178
                    }.bind(this));
179
                }
180
                if (doScroll) {
181
                    var pos = Element.cumulativeOffset($(this));
182
                    window.scrollTo(pos[0], pos[1] - 45);
183
                }
184
            }
185
        });";
186
187
        return $this->_jsHelper->getScript($script);
188
    }
189
}
190