Logout::setClearOauth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 15
rs 10
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
declare(strict_types=1);
10
11
namespace Moip\Magento2\Controller\Adminhtml\System\Config;
12
13
use Magento\Backend\App\Action\Context;
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action\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...
14
use Magento\Config\Model\ResourceModel\Config;
0 ignored issues
show
Bug introduced by
The type Magento\Config\Model\ResourceModel\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...
15
use Magento\Framework\App\Cache\Frontend\Pool;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Cache\Frontend\Pool 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 Magento\Framework\App\Cache\TypeListInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Cache\TypeListInterface 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...
17
use Magento\Framework\App\Config\ConfigResource\ConfigInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\App\Co...esource\ConfigInterface 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
use Magento\Framework\Controller\Result\JsonFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Controller\Result\JsonFactory 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...
19
use Magento\Store\Model\StoreManagerInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Store\Model\StoreManagerInterface 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...
20
use Moip\Magento2\Gateway\Config\Config as ConfigBase;
21
22
class Logout extends \Magento\Backend\App\Action
0 ignored issues
show
Bug introduced by
The type Magento\Backend\App\Action 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 $cacheTypeList;
25
26
    protected $cacheFrontendPool;
27
28
    protected $resultJsonFactory;
29
30
    protected $configInterface;
31
32
    protected $resourceConfig;
33
34
    protected $storeManager;
35
36
    protected $configBase;
37
38
    public function __construct(
39
        Context $context,
40
        TypeListInterface $cacheTypeList,
41
        Pool $cacheFrontendPool,
42
        JsonFactory $resultJsonFactory,
43
        ConfigInterface $configInterface,
44
        Config $resourceConfig,
45
        ConfigBase $configBase,
46
        StoreManagerInterface $storeManager
47
    ) {
48
        $this->cacheTypeList = $cacheTypeList;
49
        $this->cacheFrontendPool = $cacheFrontendPool;
50
        $this->resultJsonFactory = $resultJsonFactory;
51
        $this->configInterface = $configInterface;
52
        $this->resourceConfig = $resourceConfig;
53
        $this->configBase = $configBase;
54
        $this->storeManager = $storeManager;
55
        parent::__construct($context);
56
    }
57
58
    protected function _isAllowed()
59
    {
60
        return $this->_authorization->isAllowed('Moip_Magento2::logout');
61
    }
62
63
    public function execute()
64
    {
65
        $params = $this->getRequest()->getParams();
0 ignored issues
show
Unused Code introduced by
The assignment to $params is dead and can be removed.
Loading history...
66
        $resultJson = $this->resultJsonFactory->create();
67
68
        $this->setClearOauth();
69
        $this->setClearMpa();
70
        $this->cacheTypeList->cleanType('config');
71
72
        return $resultJson->setData([
73
            'messages' => 'Successfully.',
74
            'error'    => false,
75
        ]);
76
    }
77
78
    private function setClearOauth()
79
    {
80
        $environment = $this->configBase->getEnvironmentMode();
81
        $this->resourceConfig->deleteConfig(
82
            'payment/moip_magento2/oauth_'.$environment,
83
            'default',
84
            0
85
        );
86
        $this->resourceConfig->deleteConfig(
87
            'payment/moip_magento2/publickey_'.$environment,
88
            'default',
89
            0
90
        );
91
92
        return $this;
93
    }
94
95
    private function setClearMpa()
96
    {
97
        $environment = $this->configBase->getEnvironmentMode();
98
        $this->resourceConfig->deleteConfig(
99
            'payment/moip_magento2/mpa_'.$environment,
100
            'default',
101
            0
102
        );
103
        $this->resourceConfig->deleteConfig(
104
            'payment/moip_magento2/mpa_'.$environment,
105
            'default',
106
            0
107
        );
108
109
        return $this;
110
    }
111
}
112