Passed
Push — master ( 7c7d88...5359ca )
by Bob
03:13 queued 30s
created

eveApi.php ➔ makeApiRequest()   A

Complexity

Conditions 2
Paths 6

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
cc 2
eloc 14
c 3
b 2
f 0
nc 6
nop 1
dl 0
loc 23
rs 9.0856
1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Robert Sardinia
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
/**
27
 * @param $url
28
 * @return SimpleXMLElement|null
29
 */
30
function makeApiRequest($url)
31
{
32
    try {
33
        // Initialize a new request for this URL
34
        $ch = curl_init($url);
35
        // Set the options for this request
36
        curl_setopt_array($ch, array(
37
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
38
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
39
            CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate
40
            CURLOPT_TIMEOUT => 15,
41
        ));
42
        // Fetch the data from the URL
43
        $data = curl_exec($ch);
44
        // Close the connection
45
        curl_close($ch);
46
        // Return a new SimpleXMLElement based upon the received data
47
        return new SimpleXMLElement($data);
48
    } catch (Exception $e) {
49
        var_dump("EVE API Error: " . $e->getMessage());
0 ignored issues
show
Security Debugging Code introduced by
var_dump('EVE API Error: ' . $e->getMessage()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
50
        return null;
51
    }
52
}
53
54
/**
55
 * @return mixed|null
56
 */
57
58
function serverStatus() {
59
    try {
60
        // Initialize a new request for this URL
61
        $ch = curl_init("https://api.eveonline.com/server/ServerStatus.xml.aspx");
62
        // Set the options for this request
63
        curl_setopt_array($ch, array(
64
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
65
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
66
            CURLOPT_TIMEOUT => 8,
67
            CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate
68
        ));
69
        // Fetch the data from the URL
70
        $data = curl_exec($ch);
71
        // Close the connection
72
        curl_close($ch);
73
74
        $true = "true";
75
        //If server is down return false
76
        if ($data->serverOpen != "True") {
77
            return FALSE;
78
        }
79
        //If server is up return true
80
        return $true;
81
    } catch (Exception $e) {
82
        var_dump("EVE API Error: " . $e->getMessage());
0 ignored issues
show
Security Debugging Code introduced by
var_dump('EVE API Error: ' . $e->getMessage()); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
83
        return null;
84
    }
85
}