zKill.php ➔ getStartMail()   C
last analyzed

Complexity

Conditions 16
Paths 64

Size

Total Lines 27
Code Lines 16

Duplication

Lines 12
Ratio 44.44 %

Importance

Changes 0
Metric Value
cc 16
eloc 16
nc 64
nop 1
dl 12
loc 27
rs 5.0151
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
function zKillRedis()
3
{
4
    try {
5
        // Initialize a new request for this URL
6
        $ch = curl_init("http://redisq.zkillboard.com/listen.php");
7
        // Set the options for this request
8
        curl_setopt_array($ch, array(
9
            CURLOPT_FOLLOWLOCATION => true, // Yes, we want to follow a redirect
10
            CURLOPT_RETURNTRANSFER => true, // Yes, we want that curl_exec returns the fetched data
11
            CURLOPT_TIMEOUT => 8,
12
            CURLOPT_SSL_VERIFYPEER => true, // Do not verify the SSL certificate
13
        ));
14
        // Fetch the data from the URL
15
        $data = curl_exec($ch);
16
        // Close the connection
17
        curl_close($ch);
18
        $data = json_decode($data, TRUE);
19
20
    } catch (Exception $e) {
21
        return null;
22
    }
23
    return $data['package'];
24
}
25
26
function getStartMail($kmGroup)
27
{
28 View Code Duplication
    if ($kmGroup['allianceID'] === '0' && $kmGroup['lossMails'] === 'true' && $kmGroup['corpID'] !== '0') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
        $url = "https://zkillboard.com/api/no-attackers/no-items/corporationID/{$kmGroup['corpID']}/limit/1/";
30
    }
31 View Code Duplication
    if ($kmGroup['allianceID'] === '0' && $kmGroup['lossMails'] === 'false' && $kmGroup['corpID'] !== '0') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
        $url = "https://zkillboard.com/api/no-attackers/no-items/kills/corporationID/{$kmGroup['corpID']}/limit/1/";
33
    }
34 View Code Duplication
    if ($kmGroup['allianceID'] !== '0' && $kmGroup['lossMails'] === 'true' && $kmGroup['allianceID'] !== '0') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        $url = "https://zkillboard.com/api/no-attackers/no-items/allianceID/{$kmGroup['allianceID']}/limit/1/";
36
    }
37 View Code Duplication
    if ($kmGroup['allianceID'] !== '0' && $kmGroup['lossMails'] === 'false' && $kmGroup['allianceID'] !== '0') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
        $url = "https://zkillboard.com/api/no-attackers/no-items/kills/allianceID/{$kmGroup['allianceID']}/limit/1/";
39
    }
40
41
    if (!isset($url)) { // Make sure it's always set.
42
        return null;
43
    }
44
45
    $kill = json_decode(downloadData($url), true);
46
    if (null !== $kill) {
47
        foreach ($kill as $mail) {
48
            $killID = $mail['killID'];
49
            setPermCache("{$kmGroup['name']}newestKillmailID", $killID);
50
        }
51
    }
52
}
53
54
function getStartBigMail()
55
{
56
    $url = 'https://zkillboard.com/api/kills/orderDirection/desc/iskValue/10000000000/';
57
58
    if (!isset($url)) { // Make sure it's always set.
59
        return null;
60
    }
61
62
    $kill = json_decode(downloadData($url), true);
63
    if (null !== $kill) {
64
        foreach ($kill as $mail) {
65
            $killID = $mail['killID'];
66
            setPermCache('bigKillNewestKillmailID', $killID);
67
        }
68
    }
69
}