Passed
Push — master ( 785691...679eaf )
by Ross
39:28
created

Index   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 2
cbo 3
dl 0
loc 50
ccs 14
cts 16
cp 0.875
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getVerificationUrl() 0 4 1
A getMessages() 0 14 3
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\Block\Adminhtml\Adminlogin;
23
24
use Magento\Framework\Message\ManagerInterface;
25
use Magento\Framework\View\Element\Template;
26
use Rossmitchell\Twofactor\Model\TwoFactorUrls;
27
use Rossmitchell\Twofactor\Model\Urls\Fetcher;
28
29
class Index extends Template
30
{
31
    /**
32
     * @var ManagerInterface
33
     */
34
    private $messageManager;
35
    /**
36
     * @var Fetcher
37
     */
38
    private $fetcher;
39
40
    /**
41
     * Index constructor.
42
     *
43
     * @param Template\Context $context
44
     * @param Fetcher $fetcher
45
     * @param ManagerInterface $messageManager
46
     * @param array $data
47
     */
48 2
    public function __construct(
49
        Template\Context $context,
50
        Fetcher $fetcher,
51
        ManagerInterface $messageManager,
52
        array $data = []
53
    ) {
54 2
        parent::__construct($context, $data);
55 2
        $this->messageManager = $messageManager;
56 2
        $this->fetcher = $fetcher;
57 2
    }
58
59 2
    public function getVerificationUrl()
60
    {
61 2
        return $this->fetcher->getAuthenticationUrl(true);
62
    }
63
64 2
    public function getMessages()
65
    {
66 2
        $messages   = [];
67 2
        $collection = $this->messageManager->getMessages(true);
68 2
        if (null === $collection) {
69
            return $messages;
70
        }
71
72 2
        foreach ($collection->getItems() as $message) {
73
            $messages[] = $message->getText();
74 1
        }
75
76 2
        return $messages;
77
    }
78
}
79