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

AbstractLoader::getObjectManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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\Registry;
25
use Magento\TestFramework\Helper\Bootstrap;
26
27
abstract class AbstractLoader
28
{
29
    public $data;
30
31
    private $objectManager;
32
33
    public function __construct($data)
0 ignored issues
show
introduced by
Only dependency assignment operations are allowed in constructor. No other operations are allowed.
Loading history...
34
    {
35
        $this->data = $data;
36
        $this->verifyData();
37
    }
38
39
    abstract public function loadData();
40
41
    abstract public function rollBackData();
42
43
    abstract public function verifyData();
44
45
    public function createObject($className, $new = true)
46
    {
47
        $objectManager = $this->getObjectManager();
48
        if ($new === true) {
49
            return $objectManager->create($className);
0 ignored issues
show
introduced by
The direct use of ObjectManager is discouraged. Inject necessary dependencies via constructor.
Loading history...
50
        }
51
52
        return $objectManager->get($className);
0 ignored issues
show
introduced by
The direct use of ObjectManager is discouraged. Inject necessary dependencies via constructor.
Loading history...
53
    }
54
55
    private function getObjectManager()
56
    {
57
        if (null === $this->objectManager) {
58
            $this->objectManager = Bootstrap::getObjectManager();
59
        }
60
61
        return $this->objectManager;
62
    }
63
64
    public function setSecureArea()
65
    {
66
        /** @var Registry $registry */
67
        $registry = $this->createObject(Registry::class, false);
68
        $registry->unregister('isSecureArea');
69
        $registry->register('isSecureArea', true);
70
    }
71
}
72