Passed
Push — master ( b162a4...87a689 )
by Ross
03:05
created

AdminUser::getAdminUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
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\Model\Admin;
23
24
use Magento\User\Model\User;
25
26
class AdminUser
27
{
28
    /**
29
     * @var Session
30
     */
31
    private $adminSession;
32
33
    /**
34
     * AdminUser constructor.
35
     *
36
     * @param Session $adminSession
37
     */
38
    public function __construct(Session $adminSession)
39
    {
40
        $this->adminSession = $adminSession;
41
    }
42
43
    /**
44
     * @return User
45
     * @throws \Exception
46
     */
47
    public function getAdminUser()
48
    {
49
        $adminUser = $this->adminSession->getData('user');
50
        if (!$adminUser instanceof User) {
51
            throw new \Exception("No admin user found");
52
        }
53
54
        return $adminUser;
55
    }
56
57
    public function hasAdminUser()
58
    {
59
        return ($this->adminSession->hasData('user') === true);
60
    }
61
}
62