Completed
Push — master ( 682861...9e510a )
by Ross
36:42
created

Fetcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * A two factor authentication module that protects both the admin and customer logins
4
 * Copyright (C) 2017  Ross Mitchell
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\Urls;
23
24
use Magento\Framework\UrlInterface;
25
26
/**
27
 * Class Fetcher
28
 *
29
 * This is a simple wrapper class around the URL Interface class to give more meaningful names for fetching URLs
30
 */
31
class Fetcher
32
{
33
    const CUSTOMER_AUTHENTICATION_URL = 'twofactor/customerlogin/index';
34
    const CUSTOMER_VERIFICATION_URL = 'twofactor/customerlogin/verify';
35
    const CUSTOMER_ACCOUNT_URL = 'customer/account/index';
36
    const CUSTOMER_LOGIN_URL = 'customer/account/login';
37
38
    const ADMIN_AUTHENTICATION_URL = 'twofactor/adminlogin/index';
39
    const ADMIN_VERIFICATION_URL = 'twofactor/adminlogin/verify';
40
    const ADMIN_DASHBOARD_URL = 'admin/dashboard/index';
41
42
    /**
43
     * @var UrlInterface
44
     */
45
    private $url;
46
47
    /**
48
     * Fetcher constructor.
49
     *
50
     * @param UrlInterface $url
51
     */
52 42
    public function __construct(UrlInterface $url)
53
    {
54 42
        $this->url = $url;
55 42
    }
56
57
    /**
58
     * Used to get either the admin or customer two factor authentication URL
59
     *
60
     * @param bool $forAdmin - true for the admin URL, false for the customer URL
61
     * @return string
62
     */
63 24 View Code Duplication
    public function getAuthenticationUrl($forAdmin = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 24
        if ($forAdmin === true) {
66
            return $this->getUrl(self::ADMIN_AUTHENTICATION_URL);
67
        }
68
69 24
        return $this->getUrl(self::CUSTOMER_AUTHENTICATION_URL);
70
    }
71
72
    /**
73
     * Used to get either the admin or customer two factor verification URL
74
     *
75
     * @param bool $forAdmin - true for the admin URL, false for the customer URL
76
     * @return mixed
77
     */
78 20 View Code Duplication
    public function getVerificationUrl($forAdmin = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80 20
        if ($forAdmin === true) {
81
            return $this->getUrl(self::ADMIN_VERIFICATION_URL);
82
        }
83
84 20
        return $this->getUrl(self::CUSTOMER_VERIFICATION_URL);
85
    }
86
87
    /**
88
     * Used to get the URL for the customer account page
89
     *
90
     * @return string
91
     */
92 2
    public function getCustomerAccountUrl()
93
    {
94 2
        return $this->url->getUrl(self::CUSTOMER_ACCOUNT_URL);
95
    }
96
97
    /**
98
     * Used to get the URL for the admin dashboard page
99
     *
100
     * @return string
101
     */
102
    public function getAdminDashboardUrl()
103
    {
104
        return $this->url->getUrl(self::ADMIN_DASHBOARD_URL);
105
    }
106
107
    /**
108
     * Used to get the customer login URL
109
     *
110
     * @return string
111
     */
112 2
    public function getCustomerLogInUrl()
113
    {
114 2
        return $this->url->getUrl(self::CUSTOMER_LOGIN_URL);
115
    }
116
117
    /**
118
     * This is used to actually get the URL
119
     *
120
     * @param $path
121
     * @return mixed
122
     */
123 24
    private function getUrl($path)
124
    {
125 24
        return $this->url->getUrl($path);
126
    }
127
}