Completed
Push — master ( 21c1bf...8efbb2 )
by Ross
07:30
created

Configuration   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 12
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B loadData() 0 23 5
A rollBackData() 0 4 1
B verifyData() 0 11 6
1
<?php
2
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
5
 *
6
 * This file is part of Rossmitchell/Twofactor.
7
 *
8
 * Rossmitchell/Twofactor is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace Rossmitchell\Twofactor\Tests\Integration\FixtureLoader;
23
24
use Magento\Framework\App\Config\ScopeConfigInterface;
25
26
class Configuration extends AbstractLoader
27
{
28
29
    public function loadData()
30
    {
31
        /** @var \Magento\TestFramework\App\Config $configWriter */
32
        $configWriter = $this->createObject(ScopeConfigInterface::class, false);
33
        foreach ($this->data as $configValue) {
34
            $key   = $configValue['key'];
35
            $value = $configValue['value'];
36
            $scope = $configValue['scope'];
37
            switch ($scope) {
38
                case 'default':
39
                    $configWriter->setValue($key, $value, 'default');
40
                // Intentional fall through
41
                case 'website':
42
                    $configWriter->setValue($key, $value, 'website');
43
                // Intentional fall through
44
                case 'store':
45
                    $configWriter->setValue($key, $value, 'store');
46
                    break;
47
                default:
48
                    throw new \Exception("Scope must be ons of default, website, store. You used $scope");
0 ignored issues
show
introduced by
Direct throw of Exception is discouraged. Use \Magento\Framework\Exception\LocalizedException instead.
Loading history...
49
            }
50
        }
51
    }
52
53
    public function rollBackData()
0 ignored issues
show
introduced by
Empty FUNCTION statement detected
Loading history...
54
    {
55
        // TODO: Implement rollBackData() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
56
    }
57
58
    public function verifyData()
59
    {
60
        if (!is_array($this->data)) {
61
            throw new \Exception("configData must be an array");
0 ignored issues
show
introduced by
Direct throw of Exception is discouraged. Use \Magento\Framework\Exception\LocalizedException instead.
Loading history...
62
        }
63
        foreach ($this->data as $config) {
64
            if(!isset($config['key']) || !isset($config['value']) || !isset($config['scope'])) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
Coding Style introduced by
Expected "if (...) {\n"; found "if(...) {\n"
Loading history...
65
                throw new \Exception('Each row must contain key, value, and scope values');
0 ignored issues
show
introduced by
Direct throw of Exception is discouraged. Use \Magento\Framework\Exception\LocalizedException instead.
Loading history...
66
            }
67
        }
68
    }
69
}
70