Index::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 4
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\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 1
    public function __construct(
49
        Template\Context $context,
50
        Fetcher $fetcher,
51
        ManagerInterface $messageManager,
52
        array $data = []
53
    ) {
54 1
        parent::__construct($context, $data);
55 1
        $this->messageManager = $messageManager;
56 1
        $this->fetcher = $fetcher;
57 1
    }
58
59 1
    public function getVerificationUrl()
60
    {
61 1
        return $this->fetcher->getAuthenticationUrl(true);
62
    }
63
64 1
    public function getMessages()
65
    {
66 1
        $messages   = [];
67 1
        $collection = $this->messageManager->getMessages(true);
68 1
        if (null === $collection) {
69
            return $messages;
70
        }
71
72 1
        foreach ($collection->getItems() as $message) {
73
            $messages[] = $message->getText();
74
        }
75
76 1
        return $messages;
77
    }
78
}
79