Passed
Push — master ( d0848f...c51354 )
by Ross
27:06
created

Setter::setValueOnModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 3
crap 1
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\Model\Customer\Attribute;
23
24
use Magento\Customer\Api\Data\CustomerInterface;
25
use Magento\Customer\Model\Customer;
26
use Magento\Framework\Exception\InputException;
27
28
class Setter
29
{
30
31 3
    public function setValue($object, $attributeCode, $value)
32
    {
33 3
        if ($object instanceof Customer) {
34 3
            $this->setValueOnModel($object, $attributeCode, $value);
35
36 3
            return;
37
        }
38
39
        if ($object instanceof CustomerInterface) {
40
            $this->setValueOnInterface($object, $attributeCode, $value);
41
42
            return;
43
        }
44
45
        throw InputException::invalidFieldValue('object', get_class($object));
46
    }
47
48
    private function setValueOnInterface(CustomerInterface $customer, $attributeCode, $value)
49
    {
50
        $customer->setCustomAttribute($attributeCode, $value);
51
    }
52
53 3
    private function setValueOnModel(Customer $customer, $attributeCode, $value)
54
    {
55 3
        $customer->setData($attributeCode, $value);
56 3
    }
57
}
58