Passed
Push — master ( 58a1da...a6fa42 )
by Ross
29:00
created

GetQrCode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 7
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;
23
24
use Rossmitchell\Twofactor\Model\GoogleTwoFactor\QRCode as QRCodeGenerator;
25
use Rossmitchell\Twofactor\Model\Customer\Attribute\TwoFactorSecret;
26
use Rossmitchell\Twofactor\Model\Config\Customer as CustomerConfig;
27
use Magento\Customer\Api\Data\CustomerInterface;
28
29
class GetQrCode
30
{
31
    /**
32
     * @var TwoFactorSecret
33
     */
34
    private $twoFactorSecret;
35
    /**
36
     * @var CustomerConfig
37
     */
38
    private $customerConfig;
39
    /**
40
     * @var QRCodeGenerator
41
     */
42
    private $qRCode;
43
44
    /**
45
     * GetQrCode constructor.
46
     *
47
     * @param TwoFactorSecret $twoFactorSecret
48
     * @param CustomerConfig  $customerConfig
49
     * @param QRCodeGenerator $qRCode
50
     */
51 4
    public function __construct(
52
        TwoFactorSecret $twoFactorSecret,
53
        CustomerConfig $customerConfig,
54
        QRCodeGenerator $qRCode
55
    ) {
56
57 4
        $this->twoFactorSecret = $twoFactorSecret;
58 4
        $this->customerConfig  = $customerConfig;
59 4
        $this->qRCode          = $qRCode;
60 4
    }
61
62
    /**
63
     * Used to get the customers QR Code. Will return false if they don't have one, otherwise will return the image
64
     * string
65
     *
66
     * @param CustomerInterface $customer
67
     *
68
     * @return bool|string
69
     */
70 2
    public function getQrCode(CustomerInterface $customer)
71
    {
72 2
        $secret      = $this->twoFactorSecret->getValue($customer);
73 2
        $email       = $customer->getEmail();
74 2
        $companyName = $this->customerConfig->getCompanyName();
75 2
        $qrCode      = $this->qRCode->generateQRCode($companyName, $email, $secret);
76
77 2
        return $qrCode;
78
    }
79
}
80