Completed
Push — master ( a6fa42...d4a069 )
by Ross
25:43
created

GetQrCodeManagement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 40
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getQrCode() 0 9 2
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
}
70