kills::run()   C
last analyzed

Complexity

Conditions 22
Paths 44

Size

Total Lines 69
Code Lines 43

Duplication

Lines 39
Ratio 56.52 %

Importance

Changes 7
Bugs 3 Features 2
Metric Value
cc 22
eloc 43
c 7
b 3
f 2
nc 44
nop 0
dl 39
loc 69
rs 5.5836

How to fix   Long Method    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
3
namespace Sovereign\Plugins\onTimer;
4
5
use Discord\Discord;
6
use Discord\Parts\Channel\Channel;
7
use Monolog\Logger;
8
use Sovereign\Lib\Config;
9
use Sovereign\Lib\cURL;
10
use Sovereign\Lib\Db;
11
use Sovereign\Lib\Permissions;
12
use Sovereign\Lib\ServerConfig;
13
use Sovereign\Lib\Settings;
14
use Sovereign\Lib\Users;
15
16
class kills extends \Threaded implements \Collectable
17
{
18
    /**
19
     * @var Discord
20
     */
21
    protected $discord;
22
    /**
23
     * @var Logger
24
     */
25
    protected $log;
26
    /**
27
     * @var Config
28
     */
29
    protected $config;
30
    /**
31
     * @var Db
32
     */
33
    protected $db;
34
    /**
35
     * @var cURL
36
     */
37
    protected $curl;
38
    /**
39
     * @var Settings
40
     */
41
    protected $settings;
42
    /**
43
     * @var Permissions
44
     */
45
    protected $permissions;
46
    /**
47
     * @var ServerConfig
48
     */
49
    protected $serverConfig;
50
    /**
51
     * @var Users
52
     */
53
    protected $users;
54
    /**
55
     * @var array
56
     */
57
    protected $extras;
58
59 View Code Duplication
    public function __construct($discord, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
60
    {
61
        $this->discord = $discord;
62
        $this->log = $log;
63
        $this->config = $config;
64
        $this->db = $db;
65
        $this->curl = $curl;
66
        $this->settings = $settings;
67
        $this->permissions = $permissions;
68
        $this->serverConfig = $serverConfig;
69
        $this->users = $users;
70
        $this->extras = $extras;
71
    }
72
73
    public function run()
74
    {
75
        $channels = $this->db->query("SELECT * FROM killmailPosting");
76
77
        foreach ($channels as $channel) {
78
            $rowID = $channel["id"];
79
            $type = $channel["typeName"];
80
            $id = $channel["typeID"];
81
            $latest = $channel["latestKillID"];
82
            $channelID = $channel["channelID"];
83
84
            // Get the killdata
85
            $killData = json_decode($this->curl->get("https://evedata.xyz/api/killlist/latest/"));
86
87
            if (!empty($killData)) {
88
                foreach ($killData as $kill) {
89
                    if (isset($kill->killID) && ($kill->killID > $latest)) {
90
                        switch ($type) {
91 View Code Duplication
                            case "character":
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...
92
                                if ($kill->victim->characterID == $id) {
93
                                    $msg = "{$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName}) lost {$kill->victim->shipTypeName} in {$kill->solarSystemName} ({$kill->regionName}) with a total value of {$kill->totalValue}isk | https://beta.eve-kill.net/kill/{$kill->killID}/";
94
                                    $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
95
                                }
96
97
                                foreach ($kill->attackers as $attacker) {
98
                                    if ($attacker->characterID == $id && $attacker->finalBlow == 1) {
99
                                        $msg = "{$attacker->characterName} participated in killing {$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName} / {$kill->victim->shipTypeName}) in a {$attacker->shipTypeName} doing a total of {$attacker->damageDone} damage, and helped destroy {$kill->totalValue}isk | https://beta.eve-kill.net/kill/{$kill->killID}/";
100
                                        $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
101
                                    }
102
                                }
103
                                break;
104 View Code Duplication
                            case "corporation":
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...
105
                                if ($kill->victim->corporationID == $id) {
106
                                    $msg = "{$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName}) lost {$kill->victim->shipTypeName} in {$kill->solarSystemName} ({$kill->regionName}) with a total value of {$kill->totalValue}isk";
107
                                    $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
108
                                }
109
110
                                foreach ($kill->attackers as $attacker) {
111
                                    if ($attacker->corporationID == $id && $attacker->finalBlow == 1) {
112
                                        $msg = "{$attacker->characterName} participated in killing {$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName} / {$kill->victim->shipTypeName}) in a {$attacker->shipTypeName} doing a total of {$attacker->damageDone} damage, and helped destroy {$kill->totalValue}isk | https://beta.eve-kill.net/kill/{$kill->killID}/";
113
                                        $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
114
                                    }
115
                                }
116
                                break;
117 View Code Duplication
                            case "alliance":
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...
118
                                if ($kill->victim->allianceID == $id) {
119
                                    $msg = "{$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName}) lost {$kill->victim->shipTypeName} in {$kill->solarSystemName} ({$kill->regionName}) with a total value of {$kill->totalValue}isk";
120
                                    $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
121
                                }
122
123
                                foreach ($kill->attackers as $attacker) {
124
                                    if ($attacker->allianceID == $id && $attacker->finalBlow == 1) {
125
                                        $msg = "{$attacker->characterName} participated in killing {$kill->victim->characterName} ({$kill->victim->corporationName} / {$kill->victim->allianceName} / {$kill->victim->shipTypeName}) in a {$attacker->shipTypeName} doing a total of {$attacker->damageDone} damage, and helped destroy {$kill->totalValue}isk | https://beta.eve-kill.net/kill/{$kill->killID}/";
126
                                        $this->db->execute("UPDATE killmailPosting SET latestKillID = :killID WHERE id = :rowID", array(":killID" => $kill->killID, ":rowID" => $rowID));
127
                                    }
128
                                }
129
                                break;
130
                        }
131
                    }
132
                }
133
134
                if (!empty($msg)) {
135
                    /** @var Channel $chan */
136
                    $chan = Channel::find($channelID);
137
                    $chan->sendMessage($msg);
138
                }
139
            }
140
        }
141
    }
142
}
143