Code Duplication    Length = 26-28 lines in 3 locations

src/lib/eveApi.php 3 locations

@@ 33-58 (lines=26) @@
30
 * @param $url
31
 * @return SimpleXMLElement|null|string
32
 */
33
function makeApiRequest($url)
34
{
35
    $logger = new Logger('eveApi');
36
    $logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG));
37
    try {
38
        // Initialize a new request for this URL
39
        $ch = curl_init($url);
40
        // Set the options for this request
41
        curl_setopt_array($ch, array(
42
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
43
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
44
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
45
            CURLOPT_USERAGENT => 'Dramiel Discord Bot - https://github.com/shibdib/Dramiel', // Useragent
46
            CURLOPT_TIMEOUT => 15,
47
        ));
48
        // Fetch the data from the URL
49
        $data = curl_exec($ch);
50
        // Close the connection
51
        curl_close($ch);
52
        // Return a new SimpleXMLElement based upon the received data
53
        return new SimpleXMLElement($data);
54
    } catch (Exception $e) {
55
        $logger->error('EVE API Error: ' . $e->getMessage());
56
        return null;
57
    }
58
}
59
60
/**
61
 * @return mixed|null
@@ 160-187 (lines=28) @@
157
 * @return mixed
158
 */
159
////Char ID to char data via CCP
160
function characterDetails($characterID)
161
{
162
    $logger = new Logger('eveESI');
163
    $logger->pushHandler(new StreamHandler(__DIR__ . '../../log/libraryError.log', Logger::DEBUG));
164
165
    try {
166
        // Initialize a new request for this URL
167
        $ch = curl_init("https://esi.tech.ccp.is/latest/characters/{$characterID}/");
168
        // Set the options for this request
169
        curl_setopt_array($ch, array(
170
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
171
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
172
            CURLOPT_TIMEOUT => 8,
173
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
174
        ));
175
        // Fetch the data from the URL
176
        $data = curl_exec($ch);
177
        // Close the connection
178
        curl_close($ch);
179
        $data = json_decode($data, TRUE);
180
181
    } catch (Exception $e) {
182
        $logger->error('EVE ESI Error: ' . $e->getMessage());
183
        return null;
184
    }
185
186
    return $data;
187
}
188
189
/**
190
 * @param string $systemID
@@ 294-321 (lines=28) @@
291
 * @return mixed
292
 */
293
////Corp ID to corp data via CCP
294
function corpDetails($corpID)
295
{
296
    $logger = new Logger('eveESI');
297
    $logger->pushHandler(new StreamHandler(__DIR__ . '../../log/libraryError.log', Logger::DEBUG));
298
299
    try {
300
        // Initialize a new request for this URL
301
        $ch = curl_init("https://esi.tech.ccp.is/latest/corporations/{$corpID}/");
302
        // Set the options for this request
303
        curl_setopt_array($ch, array(
304
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
305
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
306
            CURLOPT_TIMEOUT => 8,
307
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
308
        ));
309
        // Fetch the data from the URL
310
        $data = curl_exec($ch);
311
        // Close the connection
312
        curl_close($ch);
313
        $data = json_decode($data, TRUE);
314
315
    } catch (Exception $e) {
316
        $logger->error('EVE ESI Error: ' . $e->getMessage());
317
        return null;
318
    }
319
320
    return $data;
321
}
322
323
/**
324
 * @param string $allianceID