These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * /classes/DomainMOD/ResellerClub.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 ResellerClub |
||
25 | { |
||
26 | public $format; |
||
27 | public $log; |
||
28 | |||
29 | public function __construct() |
||
30 | { |
||
31 | $this->format = new Format(); |
||
32 | $this->log = new Log('resellerclub.class'); |
||
33 | } |
||
34 | |||
35 | View Code Duplication | public function getApiUrl($reseller_id, $api_key, $command, $domain) |
|
36 | { |
||
37 | $base_url = 'https://httpapi.com/api/domains/details-by-name.json?auth-userid=' . $reseller_id . '&api-key=' . $api_key . '&domain-name=' . $domain; |
||
38 | if ($command == 'info') { |
||
39 | return $base_url . '&options=OrderDetails'; |
||
40 | } elseif ($command == 'dns') { |
||
41 | return $base_url . '&options=NsDetails'; |
||
42 | } else { |
||
43 | return 'Unable to build API URL'; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | View Code Duplication | public function apiCall($full_url) |
|
48 | { |
||
49 | $handle = curl_init($full_url); |
||
50 | curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true ); |
||
51 | $result = curl_exec($handle); |
||
52 | curl_close($handle); |
||
53 | return $result; |
||
54 | } |
||
55 | |||
56 | public function getFullInfo($reseller_id, $api_key, $domain) |
||
57 | { |
||
58 | $expiration_date = ''; |
||
59 | $dns_servers = array(); |
||
60 | $privacy_status = ''; |
||
61 | $autorenewal_status = ''; |
||
62 | |||
63 | $api_url = $this->getApiUrl($reseller_id, $api_key, 'info', $domain); |
||
64 | $api_results = $this->apiCall($api_url); |
||
65 | $array_results = $this->convertToArray($api_results); |
||
66 | |||
67 | // confirm that the api call was successful |
||
68 | if (isset($array_results['domainname'])) { |
||
69 | |||
70 | // get expiration date |
||
71 | $expiration_result = $array_results['endtime']; |
||
72 | $expiration_date = $this->processExpiry($expiration_result); |
||
73 | |||
74 | // get dns servers |
||
75 | $api_url = $this->getApiUrl($reseller_id, $api_key, 'dns', $domain); |
||
76 | $api_results = $this->apiCall($api_url); |
||
77 | $array_results = $this->convertToArray($api_results); |
||
78 | |||
79 | $dns_result[0] = $array_results['ns1']; |
||
0 ignored issues
–
show
|
|||
80 | $dns_result[1] = $array_results['ns2']; |
||
81 | $dns_result[2] = $array_results['ns3']; |
||
82 | $dns_result[3] = $array_results['ns4']; |
||
83 | $dns_result[4] = $array_results['ns5']; |
||
84 | $dns_result[5] = $array_results['ns6']; |
||
85 | $dns_result[6] = $array_results['ns7']; |
||
86 | $dns_result[7] = $array_results['ns8']; |
||
87 | $dns_result[8] = $array_results['ns9']; |
||
88 | $dns_result[9] = $array_results['ns10']; |
||
89 | |||
90 | $dns_servers = $this->processDns($dns_result); |
||
91 | |||
92 | // get privacy status |
||
93 | $privacy_result = $array_results['isprivacyprotected']; |
||
94 | $privacy_status = $this->processPrivacy($privacy_result); |
||
95 | |||
96 | // get auto renewal status |
||
97 | // ResellerClub only offers auto-renewal on one specific payment type, so they don't yet have the auto-renewal |
||
98 | // status as retrievable information with the API |
||
99 | $autorenewal_status = '0'; |
||
100 | |||
101 | } else { |
||
102 | |||
103 | $log_message = 'Unable to get domain details'; |
||
104 | $log_extra = array('Domain' => $domain, 'Reseller ID' => $reseller_id, 'API Key' => $this->format->obfusc($api_key)); |
||
105 | $this->log->error($log_message, $log_extra); |
||
106 | |||
107 | } |
||
108 | return array($expiration_date, $dns_servers, $privacy_status, $autorenewal_status); |
||
109 | } |
||
110 | |||
111 | public function convertToArray($api_result) |
||
112 | { |
||
113 | return json_decode($api_result, true); |
||
114 | } |
||
115 | |||
116 | public function processExpiry($expiry_result) |
||
117 | { |
||
118 | return gmdate("Y-m-d", $expiry_result); |
||
119 | } |
||
120 | |||
121 | View Code Duplication | public function processDns($dns_result) |
|
122 | { |
||
123 | $dns_servers = array(); |
||
124 | if (!empty($dns_result)) { |
||
125 | $dns_servers = array_filter($dns_result); |
||
126 | } else { |
||
127 | $dns_servers[0] = 'no.dns-servers.1'; |
||
128 | $dns_servers[1] = 'no.dns-servers.2'; |
||
129 | } |
||
130 | return $dns_servers; |
||
131 | } |
||
132 | |||
133 | public function processPrivacy($privacy_result) |
||
134 | { |
||
135 | if ($privacy_result == 'true') { |
||
136 | $privacy_status = '1'; |
||
137 | } else { |
||
138 | $privacy_status = '0'; |
||
139 | } |
||
140 | return $privacy_status; |
||
141 | } |
||
142 | |||
143 | } //@formatter:on |
||
144 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.