Completed
Push — master ( ee71a2...2d5b89 )
by Greg
05:23
created

Api::getKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 12
nc 2
nop 1
1
<?php
2
/**
3
 * /classes/DomainMOD/Api.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
//@formatter:off
22
namespace DomainMOD;
23
24
class Api
25
{
26
    public $assets;
27
    public $error;
28
    public $log;
29
    public $system;
30
31
    public function __construct()
32
    {
33
        $this->assets = new Assets();
34
        $this->error = new Error();
35
        $this->log = new Log('api.class');
36
        $this->system = new System();
37
    }
38
39
    public function getKey($account_id)
40
    {
41
        $tmpq = $this->system->db()->prepare("
42
            SELECT api_key
43
            FROM registrar_accounts
44
            WHERE id = :account_id");
45
        $tmpq->execute(['account_id' => $account_id]);
46
        $result = $tmpq->fetchColumn();
47
48
        if (!$result) {
49
50
            $log_message = 'Unable to retrieve API Key';
51
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
52
                               'Account Username' => $this->assets->getUsername($account_id));
53
            $this->log->error($log_message, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
54
            return $log_message;
55
56
        } else {
57
58
            return $result;
59
60
        }
61
    }
62
63 View Code Duplication
    public function getKeySecret($account_id)
1 ignored issue
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
        $tmpq = $this->system->db()->prepare("
66
            SELECT api_key, api_secret
67
            FROM registrar_accounts
68
            WHERE id = :account_id");
69
        $tmpq->execute(['account_id' => $account_id]);
70
        $result = $tmpq->fetch();
71
72
        if (!$result) {
73
74
            $log_message1 = 'Unable to retrieve API Key';
75
            $log_message2 = 'Unable to retrieve API Secret';
76
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
77
                               'Account Username' => $this->assets->getUsername($account_id));
78
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
            return array($log_message1, $log_message2);
81
82
        } else {
83
84
            return array($result->api_key, $result->api_secret);
85
86
        }
87
    }
88
89 View Code Duplication
    public function getUserKey($account_id)
1 ignored issue
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...
90
    {
91
        $tmpq = $this->system->db()->prepare("
92
            SELECT username, api_key
93
            FROM registrar_accounts
94
            WHERE id = :account_id");
95
        $tmpq->execute(['account_id' => $account_id]);
96
        $result = $tmpq->fetch();
97
98
        if (!$result) {
99
100
            $log_message1 = 'Unable to retrieve Username';
101
            $log_message2 = 'Unable to retrieve API Key';
102
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
103
                               'Account Username' => $this->assets->getUsername($account_id));
104
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
105
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
            return array($log_message1, $log_message2);
107
108
        } else {
109
110
            return array($result->username, $result->api_key);
111
112
        }
113
    }
114
115 View Code Duplication
    public function getUserAppSecret($account_id)
1 ignored issue
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...
116
    {
117
        $tmpq = $this->system->db()->prepare("
118
            SELECT username, api_app_name, api_secret
119
            FROM registrar_accounts
120
            WHERE id = :account_id");
121
        $tmpq->execute(['account_id' => $account_id]);
122
        $result = $tmpq->fetch();
123
124
        if (!$result) {
125
126
            $log_message1 = 'Unable to retrieve Username';
127
            $log_message2 = 'Unable to retrieve API App Name';
128
            $log_message3 = 'Unable to retrieve API Secret';
129
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
130
                               'Account Username' => $this->assets->getUsername($account_id));
131
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
132
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
133
            $this->log->error($log_message3, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
134
            return array($log_message1, $log_message2, $log_message3);
135
136
        } else {
137
138
            return array($result->username, $result->api_app_name, $result->api_secret);
139
140
        }
141
    }
142
143 View Code Duplication
    public function getUserKeyIp($account_id)
1 ignored issue
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...
144
    {
145
        $tmpq = $this->system->db()->prepare("
146
            SELECT ra.username, ra.api_key, ip.ip
147
            FROM registrar_accounts AS ra, ip_addresses AS ip
148
            WHERE ra.api_ip_id = ip.id
149
              AND ra.id = :account_id");
150
        $tmpq->execute(['account_id' => $account_id]);
151
        $result = $tmpq->fetch();
152
153
        if (!$result) {
154
155
            $log_message1 = 'Unable to retrieve Username';
156
            $log_message2 = 'Unable to retrieve API Key';
157
            $log_message3 = 'Unable to retrieve IP Address';
158
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
159
                               'Account Username' => $this->assets->getUsername($account_id));
160
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
161
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
162
            $this->log->error($log_message3, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
163
            return array($log_message1, $log_message2, $log_message3);
164
165
        } else {
166
167
            return array($result->username, $result->api_key, $result->ip);
168
169
        }
170
    }
171
172 View Code Duplication
    public function getReselleridKey($account_id)
1 ignored issue
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...
173
    {
174
        $tmpq = $this->system->db()->prepare("
175
            SELECT reseller_id, api_key
176
            FROM registrar_accounts
177
            WHERE id = :account_id");
178
        $tmpq->execute(['account_id' => $account_id]);
179
        $result = $tmpq->fetch();
180
181
        if (!$result) {
182
183
            $log_message1 = 'Unable to retrieve Reseller ID';
184
            $log_message2 = 'Unable to retrieve API Key';
185
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
186
                               'Account Username' => $this->assets->getUsername($account_id));
187
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
188
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
189
            return array($log_message1, $log_message2);
190
191
        } else {
192
193
            return array($result->reseller_id, $result->api_key);
194
195
        }
196
    }
197
198 View Code Duplication
    public function getUserPass($account_id)
1 ignored issue
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...
199
    {
200
        $tmpq = $this->system->db()->prepare("
201
            SELECT username, `password`
202
            FROM registrar_accounts
203
            WHERE id = :account_id");
204
        $tmpq->execute(['account_id' => $account_id]);
205
        $result = $tmpq->fetch();
206
207
        if (!$result) {
208
209
            $log_message1 = 'Unable to retrieve Username';
210
            $log_message2 = 'Unable to retrieve Password';
211
            $log_extra = array('Account ID' => $account_id, 'Registrar' => $this->assets->getRegistrar($account_id),
212
                               'Account Username' => $this->assets->getUsername($account_id));
213
            $this->log->error($log_message1, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
214
            $this->log->error($log_message2, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"Account...nt Username":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
215
            return array($log_message1, $log_message2);
216
217
        } else {
218
219
            return array($result->username, $result->password);
220
221
        }
222
    }
223
224 View Code Duplication
    public function getApiRegistrarName($api_registrar_id)
1 ignored issue
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...
225
    {
226
        $tmpq = $this->system->db()->prepare("
227
            SELECT `name`
228
            FROM api_registrars
229
            WHERE id = :api_registrar_id");
230
        $tmpq->execute(['api_registrar_id' => $api_registrar_id]);
231
        $result = $tmpq->fetchColumn();
232
233
        if (!$result) {
234
235
            $log_message = 'Unable to retrieve API Registrar Name';
236
            $log_extra = array('API Registrar ID' => $api_registrar_id);
237
            $this->log->error($log_message, $log_extra);
0 ignored issues
show
Documentation introduced by
$log_extra is of type array<string,?,{"API Registrar ID":"?"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
238
            return $log_message;
239
240
        } else {
241
242
            return $result;
243
244
        }
245
    }
246
247
} //@formatter:on
248