Code Duplication    Length = 34-34 lines in 3 locations

src/lib/eveApi.php 3 locations

@@ 120-153 (lines=34) @@
117
 * @return mixed
118
 */
119
////Character name to ID
120
function characterID($characterName)
121
{
122
    $logger = new Logger('eveESI');
123
    $logger->pushHandler(new StreamHandler(__DIR__ . '../../log/libraryError.log', Logger::DEBUG));
124
    $characterName = urlencode($characterName);
125
126
    try {
127
        // Initialize a new request for this URL
128
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$characterName}&categories=character&language=en-us&strict=true&datasource=tranquility");
129
        // Set the options for this request
130
        curl_setopt_array($ch, array(
131
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
132
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
133
            CURLOPT_TIMEOUT => 8,
134
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
135
        ));
136
        // Fetch the data from the URL
137
        $data = curl_exec($ch);
138
        // Close the connection
139
        curl_close($ch);
140
        $data = json_decode($data, TRUE);
141
        $id = (int)$data['character'][0];
142
143
    } catch (Exception $e) {
144
        $logger->error('EVE ESI Error: ' . $e->getMessage());
145
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$characterName}";
146
        $xml = makeApiRequest($url);
147
        foreach ($xml->result->rowset->row as $entity) {
148
            $id = $entity->attributes()->characterID;
149
        }
150
    }
151
152
    return $id;
153
}
154
155
/**
156
 * @param string $characterID
@@ 233-266 (lines=34) @@
230
 * @return mixed
231
 */
232
////Corp name to ID
233
function corpID($corpName)
234
{
235
    $logger = new Logger('eveESI');
236
    $logger->pushHandler(new StreamHandler(__DIR__ . '../../log/libraryError.log', Logger::DEBUG));
237
    $corpName = urlencode($corpName);
238
239
    try {
240
        // Initialize a new request for this URL
241
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$corpName}&categories=corporation&language=en-us&strict=true&datasource=tranquility");
242
        // Set the options for this request
243
        curl_setopt_array($ch, array(
244
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
245
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
246
            CURLOPT_TIMEOUT => 8,
247
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
248
        ));
249
        // Fetch the data from the URL
250
        $data = curl_exec($ch);
251
        // Close the connection
252
        curl_close($ch);
253
        $data = json_decode($data, TRUE);
254
        $id = (int)$data['corporation'][0];
255
256
    } catch (Exception $e) {
257
        $logger->error('EVE ESI Error: ' . $e->getMessage());
258
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$corpName}";
259
        $xml = makeApiRequest($url);
260
        foreach ($xml->result->rowset->row as $entity) {
261
            $id = $entity->attributes()->characterID;
262
        }
263
    }
264
265
    return $id;
266
}
267
268
269
/**
@@ 367-400 (lines=34) @@
364
 * @return mixed
365
 */
366
////System name to ID
367
function systemID($systemName)
368
{
369
    $logger = new Logger('eveESI');
370
    $logger->pushHandler(new StreamHandler(__DIR__ . '../../log/libraryError.log', Logger::DEBUG));
371
    $systemName = urlencode($systemName);
372
373
    try {
374
        // Initialize a new request for this URL
375
        $ch = curl_init("https://esi.tech.ccp.is/latest/search/?search={$systemName}&categories=solarsystem&language=en-us&strict=true&datasource=tranquility");
376
        // Set the options for this request
377
        curl_setopt_array($ch, array(
378
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
379
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
380
            CURLOPT_TIMEOUT => 8,
381
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
382
        ));
383
        // Fetch the data from the URL
384
        $data = curl_exec($ch);
385
        // Close the connection
386
        curl_close($ch);
387
        $data = json_decode($data, TRUE);
388
        $id = (int)$data['solarsystem'][0];
389
390
    } catch (Exception $e) {
391
        $logger->error('EVE ESI Error: ' . $e->getMessage());
392
        $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$systemName}";
393
        $xml = makeApiRequest($url);
394
        foreach ($xml->result->rowset->row as $entity) {
395
            $id = $entity->attributes()->characterID;
396
        }
397
    }
398
399
    return $id;
400
}
401
402
/**
403
 * @param string $typeID