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

GetQrCodeManagement::getQrCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.032
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