Passed
Pull Request — master (#8)
by Bob
03:01
created

eveApi.php ➔ makeApiRequest()   B

Complexity

Conditions 2
Paths 6

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 3 Features 0
Metric Value
cc 2
eloc 14
c 4
b 3
f 0
nc 6
nop 1
dl 0
loc 24
rs 8.9713
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
 *
29
 * @return SimpleXMLElement|null
30
 */
31
function makeApiRequest($url)
32
{
33
    try {
34
        // Initialize a new request for this URL
35
        $ch = curl_init($url);
36
        // Set the options for this request
37
        curl_setopt_array($ch, [
38
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
39
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
40
            CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate
41
            CURLOPT_TIMEOUT        => 15,
42
        ]);
43
        // Fetch the data from the URL
44
        $data = curl_exec($ch);
45
        // Close the connection
46
        curl_close($ch);
47
        // Return a new SimpleXMLElement based upon the received data
48
        return new SimpleXMLElement($data);
49
    } catch (Exception $e) {
50
        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...
51
52
        return;
53
    }
54
}
55
56
/**
57
 * @return mixed|null
58
 */
59
function serverStatus()
60
{
61
    try {
62
        // Initialize a new request for this URL
63
        $ch = curl_init('https://api.eveonline.com/server/ServerStatus.xml.aspx');
64
        // Set the options for this request
65
        curl_setopt_array($ch, [
66
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
67
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
68
            CURLOPT_TIMEOUT        => 8,
69
            CURLOPT_SSL_VERIFYPEER => false, // Do not verify the SSL certificate
70
        ]);
71
        // Fetch the data from the URL
72
        $data = curl_exec($ch);
73
        // Close the connection
74
        curl_close($ch);
75
76
        $true = 'true';
77
        //If server is down return false
78
        if ($data->serverOpen != 'True') {
79
            return false;
80
        }
81
        //If server is up return true
82
        return $true;
83
    } catch (Exception $e) {
84
        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...
85
86
        return;
87
    }
88
}
89