Oauth   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 44
c 2
b 0
f 0
dl 0
loc 155
rs 10
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getButtonHtml() 0 12 1
A getAjaxUrl() 0 3 1
A getInfoTextBtn() 0 17 3
A getUrlAuthorize() 0 6 1
A getUrlToConnect() 0 20 2
A render() 0 5 1
A __construct() 0 6 1
A getTypeJs() 0 7 2
A _getElementHtml() 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\Backend\Block\Template\Context;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Block\Template\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...
12
use Magento\Config\Block\System\Config\Form\Field;
0 ignored issues
show
Bug introduced by
The type Magento\Config\Block\System\Config\Form\Field 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\Data\Form\Element\AbstractElement;
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...
14
use Moip\Magento2\Gateway\Config\Config;
15
16
/**
17
 * Class Oauth - Defines oAuth session actions.
18
 */
19
class Oauth extends Field
20
{
21
    /**
22
     * @var template
0 ignored issues
show
Bug introduced by
The type Moip\Magento2\Block\Admi...\System\Config\template 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...
23
     */
24
    protected $_template = 'Moip_Magento2::system/config/oauth.phtml';
25
26
    /**
27
     * @var config
28
     */
29
    protected $config;
30
31
    /**
32
     * @param Config
33
     * @param Context
34
     */
35
    public function __construct(
36
        Config $config,
37
        Context $context
38
    ) {
39
        $this->config = $config;
40
        parent::__construct($context);
41
    }
42
43
    /*
44
     * Render
45
     *
46
     * @param $element
47
     *
48
     * @return string
49
     */
50
    public function render(AbstractElement $element)
51
    {
52
        $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
53
54
        return parent::render($element);
55
    }
56
57
    /*
58
     * Elment Html
59
     *
60
     * @param $element
61
     *
62
     * @return string
63
     */
64
    protected function _getElementHtml(AbstractElement $element)
65
    {
66
        return $this->_toHtml();
67
    }
68
69
    /*
70
     * Ajax Url
71
     *
72
     * @return url
0 ignored issues
show
Bug introduced by
The type Moip\Magento2\Block\Adminhtml\System\Config\url 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...
73
     */
74
    public function getAjaxUrl()
75
    {
76
        return $this->getUrl('moip/system_config/logout');
77
    }
78
79
    /*
80
     * Url Authorize
81
     *
82
     * @return url
83
     */
84
    public function getUrlAuthorize()
85
    {
86
        $baseUri = Config::OAUTH_URI;
87
        $storeUri = $this->getUrl('moip/system_config/oauth');
88
89
        return $baseUri.'?client_id='.$storeUri;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $baseUri . '?client_id=' . $storeUri returns the type string which is incompatible with the documented return type Moip\Magento2\Block\Adminhtml\System\Config\url.
Loading history...
90
    }
91
92
    /*
93
     * Button Html
94
     *
95
     * @return string
96
     */
97
    public function getButtonHtml()
98
    {
99
        $button = $this->getLayout()->createBlock(
100
            \Magento\Backend\Block\Widget\Button::class
0 ignored issues
show
Bug introduced by
The type Magento\Backend\Block\Widget\Button 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...
101
        )->setData(
102
            [
103
                'id'    => 'oauth',
104
                'label' => __($this->getInfoTextBtn()),
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

104
                'label' => /** @scrutinizer ignore-call */ __($this->getInfoTextBtn()),
Loading history...
105
            ]
106
        );
107
108
        return $button->toHtml();
109
    }
110
111
    /*
112
     * Info Text Button
113
     *
114
     * @return string
115
     */
116
    public function getInfoTextBtn()
117
    {
118
        $environment = $this->config->getEnvironmentMode();
119
        $oauth = $this->config->getMerchantGatewayOauth();
120
        $label = __('Production');
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

120
        $label = /** @scrutinizer ignore-call */ __('Production');
Loading history...
121
122
        if ($environment === Config::ENVIRONMENT_SANDBOX) {
123
            $label = __('Environment for tests');
124
        }
125
126
        $text = sprintf(__('Authorize in %s'), $label);
127
128
        if ($oauth) {
129
            $text = sprintf(__('Disallow in %s'), $label);
130
        }
131
132
        return $text;
133
    }
134
135
    /*
136
     * Type Js
137
     *
138
     * @return string
139
     */
140
    public function getTypeJs()
141
    {
142
        if ($this->config->getMerchantGatewayOauth()) {
143
            return 'clear';
144
        }
145
146
        return 'getautorization';
147
    }
148
149
    /*
150
     * Url to connect
151
     *
152
     * @return string
153
     */
154
    public function getUrlToConnect()
155
    {
156
        $redirectUri = $this->getUrlAuthorize();
157
        $endpointOauth = Config::ENDPOINT_OAUTH_PRODUCTION;
158
        $appId = Config::APP_ID_PRODUCTION;
159
        $scope = Config::OAUTH_SCOPE;
160
        $responseType = 'code';
161
162
        if ($this->config->getEnvironmentMode() === Config::ENVIRONMENT_SANDBOX) {
163
            $endpointOauth = Config::ENDPOINT_OAUTH_SANDBOX;
164
            $appId = Config::APP_ID_SANDBOX;
165
        }
166
167
        $link = $endpointOauth;
168
        $link .= '?response_type='.$responseType;
169
        $link .= '&client_id='.$appId;
170
        $link .= '&redirect_uri='.$redirectUri;
171
        $link .= '&scope='.$scope;
172
173
        return $link;
174
    }
175
}
176