Passed
Push — master ( 785691...679eaf )
by Ross
39:28
created

Fetcher::getCustomerAccountUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
    const ADMIN_LOGIN_URL = 'admin/index/index';
42
43
    /**
44
     * @var UrlInterface
45
     */
46
    private $url;
47
48
    /**
49
     * Fetcher constructor.
50
     *
51
     * @param UrlInterface $url
52
     */
53 64
    public function __construct(UrlInterface $url)
54
    {
55 64
        $this->url = $url;
56 64
    }
57
58
    /**
59
     * Used to get either the admin or customer two factor authentication URL
60
     *
61
     * @param bool $forAdmin - true for the admin URL, false for the customer URL
62
     * @return string
63
     */
64 30 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...
65
    {
66 30
        if ($forAdmin === true) {
67 6
            return $this->getUrl(self::ADMIN_AUTHENTICATION_URL);
68
        }
69
70 24
        return $this->getUrl(self::CUSTOMER_AUTHENTICATION_URL);
71
    }
72
73
    /**
74
     * Used to get either the admin or customer two factor verification URL
75
     *
76
     * @param bool $forAdmin - true for the admin URL, false for the customer URL
77
     * @return mixed
78
     */
79 24 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...
80
    {
81 24
        if ($forAdmin === true) {
82 4
            return $this->getUrl(self::ADMIN_VERIFICATION_URL);
83
        }
84
85 20
        return $this->getUrl(self::CUSTOMER_VERIFICATION_URL);
86
    }
87
88
    /**
89
     * Used to get the URL for the customer account page
90
     *
91
     * @return string
92
     */
93 2
    public function getCustomerAccountUrl()
94
    {
95 2
        return $this->getUrl(self::CUSTOMER_ACCOUNT_URL);
96
    }
97
98
    /**
99
     * Used to get the URL for the admin dashboard page
100
     *
101
     * @return string
102
     */
103 6
    public function getAdminDashboardUrl()
104
    {
105 6
        return $this->getUrl(self::ADMIN_DASHBOARD_URL);
106
    }
107
108
    /**
109
     * Used to get the customer login URL
110
     *
111
     * @return string
112
     */
113 2
    public function getCustomerLogInUrl()
114
    {
115 2
        return $this->getUrl(self::CUSTOMER_LOGIN_URL);
116
    }
117
118 4
    public function getAdminLogInUrl()
119
    {
120 4
        return $this->getUrl(self::ADMIN_LOGIN_URL);
121
    }
122
    /**
123
     * This is used to actually get the URL
124
     *
125
     * @param $path
126
     * @return mixed
127
     */
128 40
    private function getUrl($path)
129
    {
130 40
        return $this->url->getUrl($path);
131
    }
132
}
133