Completed
Push — master ( 70bc12...725ad3 )
by Ross
35:29
created

Index::displayCurrentCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Customerlogin;
23
24
use Magento\Framework\View\Element\Template;
25
use Magento\Framework\View\Element\Template\Context;
26
use Rossmitchell\Twofactor\Model\Customer\Attribute\TwoFactorSecret;
27
use Rossmitchell\Twofactor\Model\Customer\Customer;
28
use Rossmitchell\Twofactor\Model\GoogleTwoFactor\QRCode;
29
use Rossmitchell\Twofactor\Model\GoogleTwoFactor\Secret;
30
31
class Index extends Template
32
{
33
    /**
34
     * @var Secret
35
     */
36
    private $secret;
37
    /**
38
     * @var QRCode
39
     */
40
    private $code;
41
    /**
42
     * @var TwoFactorSecret
43
     */
44
    private $twoFactorSecret;
45
    /**
46
     * @var Customer
47
     */
48
    private $customerGetter;
49
50
    /**
51
     * Index constructor.
52
     *
53
     * @param Context         $context
54
     * @param Secret          $secret
55
     * @param QRCode          $code
56
     * @param TwoFactorSecret $twoFactorSecret
57
     * @param Customer        $customerGetter
58
     * @param array           $data
59
     */
60 2 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
        Context $context,
62
        Secret $secret,
63
        QRCode $code,
64
        TwoFactorSecret $twoFactorSecret,
65
        Customer $customerGetter,
66
        array $data = []
67
    ) {
68 2
        parent::__construct($context, $data);
69 2
        $this->secret          = $secret;
70 2
        $this->code            = $code;
71 2
        $this->twoFactorSecret = $twoFactorSecret;
72 2
        $this->customerGetter  = $customerGetter;
73 2
    }
74
75 2
    public function getCustomer()
76
    {
77 2
        return $this->customerGetter->getCustomer();
78
    }
79
80 2
    public function getSecret($customer)
81
    {
82 2
        $secret = false;
83
84 2
        if ($this->twoFactorSecret->hasValue($customer)) {
85 2
            $secret = $this->twoFactorSecret->getValue($customer);
86 1
        }
87
88 2
        return $secret;
89
    }
90
91 2
    public function getQRCode($company, $email, $secret)
92
    {
93 2
        return $this->code->generateQRCode($company, $email, $secret);
94
    }
95
96 2
    public function displayCurrentCode($secret)
97
    {
98 2
        return $this->code->displayCurrentCode($secret);
99
    }
100
}
101