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

GetQrCodeManagement::getQrCode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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