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

GetQrCode::buildResponseForCustomer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 0
cts 11
cp 0
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * A Magento 2 module named Rossmitchell/Twofactor
4
 * Copyright (C) 2017
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\Api\ResponseBuilder;
23
24
use Magento\Customer\Api\Data\CustomerInterface;
25
use Rossmitchell\Twofactor\Api\Response\GetQrCodeInterfaceFactory;
26
use Rossmitchell\Twofactor\Model\Customer\Attribute\IsUsingTwoFactor;
27
use Rossmitchell\Twofactor\Model\Customer\Attribute\TwoFactorSecret;
28
use Rossmitchell\Twofactor\Model\Customer\Customer;
29
use Rossmitchell\Twofactor\Model\Customer\GetQrCode as GetQrCodeFetcher;
30
use Rossmitchell\Twofactor\Model\GoogleTwoFactor\QRCode;
31
32
class GetQrCode
33
{
34
    /**
35
     * @var GetQrCodeInterfaceFactory
36
     */
37
    private $response;
38
    /**
39
     * @var IsUsingTwoFactor
40
     */
41
    private $isUsingTwoFactor;
42
    /**
43
     * @var TwoFactorSecret
44
     */
45
    private $twoFactorSecret;
46
    /**
47
     * @var QRCode
48
     */
49
    private $qrCode;
50
    /**
51
     * @var GetQrCodeFetcher
52
     */
53
    private $getQrCode;
54
55
    /**
56
     * GetQrCode constructor.
57
     *
58
     * @param GetQrCodeInterfaceFactory $response
59
     * @param IsUsingTwoFactor          $isUsingTwoFactor
60
     * @param TwoFactorSecret           $twoFactorSecret
61
     * @param QRCode                    $qrCode
62
     * @param GetQrCodeFetcher          $getQrCode
63
     */
64
    public function __construct(
65
        GetQrCodeInterfaceFactory $response,
66
        IsUsingTwoFactor $isUsingTwoFactor,
67
        TwoFactorSecret $twoFactorSecret,
68
        QRCode $qrCode,
69
        GetQrCodeFetcher $getQrCode
70
    ) {
71
72
        $this->response = $response;
73
        $this->isUsingTwoFactor = $isUsingTwoFactor;
74
        $this->twoFactorSecret = $twoFactorSecret;
75
        $this->qrCode = $qrCode;
76
        $this->getQrCode = $getQrCode;
77
    }
78
79
    public function buildResponseForCustomer(CustomerInterface $customer)
80
    {
81
        $response = $this->response->create();
82
        $response->setEmail($customer->getEmail());
83
        $isUsing = $this->isUsingTwoFactor($customer);
84
        $response->setIsUsingTwoFactor($isUsing);
85
86
        if ($isUsing === true) {
87
            $response->setQrCode($this->getQrCode->getQrCode($customer));
88
        }
89
90
        return $response;
91
    }
92
93 View Code Duplication
    private function isUsingTwoFactor(CustomerInterface $customer)
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...
94
    {
95
        $hasValue = $this->isUsingTwoFactor->hasValue($customer);
96
        if ($hasValue === false) {
97
            return false;
98
        }
99
100
        return $this->isUsingTwoFactor->getValue($customer);
101
    }
102
}
103