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

Customer::loadData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 9
nc 3
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\Customer\Model\CustomerFactory;
25
26
class Customer extends AbstractLoader
27
{
28
0 ignored issues
show
introduced by
Code must not contain multiple empty lines in a row; found 2 empty lines.
Loading history...
29
30
    public function loadData()
31
    {
32
        echo "Loading customer Data".PHP_EOL;
0 ignored issues
show
introduced by
Use of echo language construct is discouraged.
Loading history...
33
        /** @var CustomerFactory $customerFactory */
34
        $customerFactory = $this->createObject(CustomerFactory::class);
35
        foreach ($this->data as $customerData) {
36
            $customer = $customerFactory->create();
37
            foreach ($customerData as $key => $value) {
38
                $customer->setData($key, $value);
39
            }
40
            $customer->isObjectNew(true);
41
            $customer->save();
0 ignored issues
show
introduced by
Model LSD method save() detected in loop
Loading history...
42
        }
43
44
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
45
46
    public function rollBackData()
47
    {
48
        echo "Rolling back customer Data".PHP_EOL;
0 ignored issues
show
introduced by
Use of echo language construct is discouraged.
Loading history...
49
        /** @var CustomerFactory $customerFactory */
50
        $customerFactory = $this->createObject(CustomerFactory::class);
51
        $this->setSecureArea();
52
        foreach ($this->data as $customerData) {
53
            $customer = $customerFactory->create();
54
            $customer->load($customerData['id']);
0 ignored issues
show
introduced by
Model LSD method load() detected in loop
Loading history...
55
            $customer->delete();
0 ignored issues
show
introduced by
Model LSD method delete() detected in loop
Loading history...
56
        }
57
    }
58
59
    public function verifyData()
60
    {
61
        foreach ($this->data as $customerData) {
62
            if (!isset($customerData['id'])) {
63
                throw new \Exception("You must set an ID for each customer");
0 ignored issues
show
introduced by
Direct throw of Exception is discouraged. Use \Magento\Framework\Exception\LocalizedException instead.
Loading history...
64
            }
65
        }
66
    }
67
}
68