Code Duplication    Length = 34-34 lines in 3 locations

src/lib/eveApi.php 3 locations

@@ 125-158 (lines=34) @@
122
 *
123
 * @return string
124
 */
125
function characterID($characterName)
126
{
127
    $logger = new Logger('eveESI');
128
    $logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG));
129
    $characterName = rawurlencode(urldecode($characterName));
130
131
    try {
132
        // Initialize a new request for this URL
133
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$characterName}&categories=character&language=en-us&strict=true&datasource=tranquility");
134
        // Set the options for this request
135
        curl_setopt_array($ch, array(
136
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
137
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
138
            CURLOPT_TIMEOUT => 8,
139
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
140
        ));
141
        // Fetch the data from the URL
142
        $data = curl_exec($ch);
143
        // Close the connection
144
        curl_close($ch);
145
        $data = json_decode($data, TRUE);
146
        $id = (int) $data['character'][0];
147
148
    } catch (Exception $e) {
149
        $logger->error('EVE ESI Error: ' . $e->getMessage());
150
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$characterName}";
151
        $xml = makeApiRequest($url);
152
        foreach ($xml->result->rowset->row as $entity) {
153
            $id = $entity->attributes()->characterID;
154
        }
155
    }
156
157
    return $id;
158
}
159
160
/**
161
 * @param string $characterID
@@ 309-342 (lines=34) @@
306
/**
307
 * @param string $corpName
308
 */
309
function corpID($corpName)
310
{
311
    $logger = new Logger('eveESI');
312
    $logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG));
313
    $corpName = urlencode($corpName);
314
315
    try {
316
        // Initialize a new request for this URL
317
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?categories=corporation&datasource=tranquility&language=en-us&search={$corpName}&strict=true");
318
        // Set the options for this request
319
        curl_setopt_array($ch, array(
320
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
321
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
322
            CURLOPT_TIMEOUT => 8,
323
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
324
        ));
325
        // Fetch the data from the URL
326
        $data = curl_exec($ch);
327
        // Close the connection
328
        curl_close($ch);
329
        $data = json_decode($data, TRUE);
330
        $id = (int) $data['corporation'][0];
331
332
    } catch (Exception $e) {
333
        $logger->error('EVE ESI Error: ' . $e->getMessage());
334
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$corpName}";
335
        $xml = makeApiRequest($url);
336
        foreach ($xml->result->rowset->row as $entity) {
337
            $id = $entity->attributes()->characterID;
338
        }
339
    }
340
341
    return $id;
342
}
343
344
345
/**
@@ 443-476 (lines=34) @@
440
 * @return mixed
441
 */
442
////System name to ID
443
function systemID($systemName)
444
{
445
    $logger = new Logger('eveESI');
446
    $logger->pushHandler(new StreamHandler(__DIR__ . '/../../log/libraryError.log', Logger::DEBUG));
447
    $systemName = urlencode($systemName);
448
449
    try {
450
        // Initialize a new request for this URL
451
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$systemName}&categories=solarsystem&language=en-us&strict=true&datasource=tranquility");
452
        // Set the options for this request
453
        curl_setopt_array($ch, array(
454
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
455
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
456
            CURLOPT_TIMEOUT => 8,
457
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
458
        ));
459
        // Fetch the data from the URL
460
        $data = curl_exec($ch);
461
        // Close the connection
462
        curl_close($ch);
463
        $data = json_decode($data, TRUE);
464
        $id = (int) $data['solarsystem'][0];
465
466
    } catch (Exception $e) {
467
        $logger->error('EVE ESI Error: ' . $e->getMessage());
468
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$systemName}";
469
        $xml = makeApiRequest($url);
470
        foreach ($xml->result->rowset->row as $entity) {
471
            $id = $entity->attributes()->characterID;
472
        }
473
    }
474
475
    return $id;
476
}
477
478
/**
479
 * @param string $typeID