Completed
Push — master ( 479bd3...ba046f )
by Ross
24:36
created

GetQrCodeManagement   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 43
ccs 8
cts 9
cp 0.8889
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\Customer\Api\Data\CustomerInterface;
25
use Magento\Framework\Exception\AuthenticationException;
26
use Rossmitchell\Twofactor\Api\Request\GetQrCodeManagementInterface;
27
use Rossmitchell\Twofactor\Api\Response\GetQrCodeInterface;
28
use Rossmitchell\Twofactor\Model\Api\ResponseBuilder\GetQrCode;
29
use Rossmitchell\Twofactor\Model\Customer\Customer;
30
31
class GetQrCodeManagement implements GetQrCodeManagementInterface
32
{
33
    /**
34
     * @var GetQrCode
35
     */
36
    private $responseBuilder;
37
    /**
38
     * @var Customer
39
     */
40
    private $customer;
41
42
    /**
43
     * GetQrCodeManagement constructor.
44
     *
45
     * @param Customer  $customer
46
     * @param GetQrCode $responseBuilder
47
     */
48 3
    public function __construct(
49
        Customer $customer,
50
        GetQrCode $responseBuilder
51
    ) {
52 3
        $this->responseBuilder = $responseBuilder;
53 3
        $this->customer = $customer;
54 3
    }
55
56
    /**
57
     * GET for getQrCode api
58
     *
59
     * @param string $customerId
60
     *
61
     * @return GetQrCodeInterface
62
     * @throws AuthenticationException
63
     */
64 3
    public function getQrCode($customerId)
65
    {
66 3
        $customer = $this->customer->getCustomerById($customerId);
67 3
        if (null === $customer->getId()) {
68
            throw new AuthenticationException(__('You must be logged in to access your QR Code'));
69
        }
70
71 3
        return $this->responseBuilder->buildResponseForCustomer($customer);
72
    }
73
}
74