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

GetQrCodeManagement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3
ccs 0
cts 28
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B getQrCode() 0 26 4
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\Requests;
23
24
use Magento\Framework\Exception\AuthenticationException;
25
use Rossmitchell\Twofactor\Api\Request\GetQrCodeManagementInterface;
26
use Rossmitchell\Twofactor\Api\Response\GetQrCodeInterface;
27
use Rossmitchell\Twofactor\Model\Api\ResponseBuilder\GetQrCode;
28
use Rossmitchell\Twofactor\Model\Customer\Customer;
29
30
class GetQrCodeManagement implements GetQrCodeManagementInterface
31
{
32
    /**
33
     * @var GetQrCode
34
     */
35
    private $responseBuilder;
36
    /**
37
     * @var Customer
38
     */
39
    private $customer;
40
41
    /**
42
     * GetQrCodeManagement constructor.
43
     *
44
     * @param Customer  $customer
45
     * @param GetQrCode $responseBuilder
46
     */
47
    public function __construct(
48
        Customer $customer,
49
        GetQrCode $responseBuilder
50
    ) {
51
        $this->responseBuilder = $responseBuilder;
52
        $this->customer = $customer;
53
    }
54
55
    /**
56
     * GET for getQrCode api
57
     * @return GetQrCodeInterface
58
     * @throws AuthenticationException
59
     */
60
    public function getQrCode()
61
    {
62
        $customer = $this->customer->getCustomer();
63
        if ($customer === false) {
64
            throw new AuthenticationException(__('Could not find a customer'));
65
        }
66
67
        return $this->responseBuilder->buildResponseForCustomer($customer);
68
69
        $hasTwoFactor = $this->isUsingTwoFactor->hasValue($customer);
0 ignored issues
show
Unused Code introduced by
$hasTwoFactor = $this->i...r->hasValue($customer); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
70
        $response->setEmail($customer->getEmail());
71
        if ($hasTwoFactor === false) {
72
            $response->setIsUsingTwoFactor(false);
73
74
            return $response;
75
        }
76
77
        $isUsingTwoFactor = $this->isUsingTwoFactor->getValue($customer);
78
        $response->setIsUsingTwoFactor($isUsingTwoFactor);
79
        if ($isUsingTwoFactor === true) {
80
            $secret = $this->twoFactorSecret->getValue($customer);
81
            $response->setQrCode($this->qrCode->displayCurrentCode($secret));
82
        }
83
84
        return $response;
85
    }
86
}
87