Passed
Branch master (f31379)
by
unknown
02:35
created

notifications   D

Complexity

Total Complexity 84

Size/Duplication

Total Lines 520
Duplicated Lines 24.62 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 128
loc 520
rs 4.8717
c 0
b 0
f 0
wmc 84
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 21 2
A tick() 16 16 3
F getNotifications() 112 374 76
A getNotificationText() 0 8 1
A onMessage() 0 3 1
A information() 0 7 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like notifications often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use notifications, and based on these observations, apply Extract Interface, too.

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
use discord\discord;
28
29
/**
30
 * Class notifications
31
 * @property  keyID
32
 * @property  vCode
33
 * @property string allianceOnly
34
 */
35
class notifications
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
36
{
37
    /**
38
     * @var
39
     */
40
    var $config;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $config.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
41
    /**
42
     * @var
43
     */
44
    var $discord;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $discord.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
45
    /**
46
     * @var
47
     */
48
    var $logger;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $logger.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
49
    /**
50
     * @var
51
     */
52
    var $nextCheck;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $nextCheck.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
53
    /**
54
     * @var
55
     */
56
    var $keys;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $keys.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
57
    /**
58
     * @var
59
     */
60
    var $keyCount;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $keyCount.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
61
    /**
62
     * @var
63
     */
64
    var $toDiscordChannel;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $toDiscordChannel.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
65
    /**
66
     * @var
67
     */
68
    var $newestNotificationID;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $newestNotificationID.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
69
    /**
70
     * @var
71
     */
72
    var $maxID;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $maxID.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
73
    /**
74
     * @var
75
     */
76
    var $charApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $charApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
77
    /**
78
     * @var
79
     */
80
    var $corpApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $corpApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
81
    /**
82
     * @var
83
     */
84
    var $alliApi;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $alliApi.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
85
    public $fuelChannel;
86
    public $fuelSkip;
87
    public $keyID;
88
    public $vCode;
89
    public $characterID;
90
    public $guild;
91
92
    /**
93
     * @param $config
94
     * @param $discord
95
     * @param $logger
96
     */
97
    function init($config, $discord, $logger)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
98
    {
99
        $this->config = $config;
100
        $this->discord = $discord;
101
        $this->logger = $logger;
102
        $this->toDiscordChannel = $config["plugins"]["notifications"]["channelID"];
103
        $this->allianceOnly = strtolower($config["plugins"]["notifications"]["allianceOnly"]);
104
        $this->fuelChannel = $config["plugins"]["fuel"]["channelID"];
105
        $this->fuelSkip = $config["plugins"]["fuel"]["skip"];
106
        $this->newestNotificationID = getPermCache("newestNotificationID");
107
        $this->maxID = 0;
108
        $this->keyID = $config["eve"]["apiKeys"]["user1"]["keyID"];
109
        $this->vCode = $config["eve"]["apiKeys"]["user1"]["vCode"];
110
        $this->characterID = $config["eve"]["apiKeys"]["user1"]["characterID"];
111
        $this->guild = $config["bot"]["guild"];
112
        //Refresh check at bot start
113
        setPermCache("notificationsLastChecked{$this->keyID}",  time() - 5);
114
        if (is_null($this->allianceOnly)) {
115
            $this->allianceOnly = "false";
116
        }
117
    }
118
119
    /**
120
     *
121
     */
122 View Code Duplication
    function tick()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
123
    {
124
        // What was the servers last reported state
125
        $lastStatus = getPermCache("serverState");
126
        if ($lastStatus == "online") {
127
            $lastChecked = getPermCache("notificationsLastChecked{$this->keyID}");
128
            $keyID = $this->keyID;
129
            $vCode = $this->vCode;
130
            $characterID = $this->characterID;
131
132
            if ($lastChecked <= time()) {
133
                $this->logger->addInfo("Notifications: Checking API Key {$keyID} for notifications..");
134
                $this->getNotifications($keyID, $vCode, $characterID);
135
            }
136
        }
137
    }
138
139
    /**
140
     * @param $keyID
141
     * @param $vCode
142
     * @param $characterID
143
     * @return null
144
     */
145
    function getNotifications($keyID, $vCode, $characterID)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
146
    {
147
        $discord = $this->discord;
0 ignored issues
show
Unused Code introduced by
$discord is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
148
149
        try {
150
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
151
            $xml = makeApiRequest($url);
152
            date_default_timezone_set('UTC');
153
            $cached = $xml->cachedUntil[0];
154
            $baseUnix = strtotime($cached);
155
            $cacheClr = $baseUnix - 13500;
156
            if (!isset($this->fuelChannel)) {
157
                $this->fuelChannel = $this->toDiscordChannel;
158
            }
159 View Code Duplication
            if ($cacheClr <= time()) {
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...
160
                $weirdTime = time() + 1830;
161
                $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime);
162
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
163
            } else {
164
                $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr);
165
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
166
            }
167
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
168
                "SimpleXMLElement", LIBXML_NOCDATA)), true);
169
            $data = $data["result"]["rowset"]["row"];
170
            // If there is no data, just quit..
171
            if (empty($data)) {
172
                return;
173
            }
174
            $fixedData = array();
175
            // Sometimes there is only ONE notification, so.. yeah..
176
            if (isset($data["@attributes"])) {
177
                $fixedData[] = $data["@attributes"];
178
            }
179
            if (count($data) > 1) {
180
                foreach ($data as $multiNotif) {
181
                    $fixedData[] = $multiNotif["@attributes"];
182
                }
183
            }
184
            foreach ($fixedData as $notification) {
185
                $notificationID = $notification["notificationID"];
186
                $typeID = $notification["typeID"];
187
                $sentDate = $notification["sentDate"];
188
                $channelID = $this->toDiscordChannel;
189
                if ($notificationID > $this->newestNotificationID) {
190
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID,
191
                        $notificationID));
192
                    switch ($typeID) {
193
                        case 1: // Old
194
                            $msg = "skip";
195
                            break;
196
                        case 2: // biomassed
197
                            $msg = "skip";
198
                            break;
199
                        case 3: // medal awarded
200
                            $msg = "skip";
201
                            break;
202
                        case 4: // alliance bill
203
                            $msg = "skip";
204
                            break;
205 View Code Duplication
                        case 5: // War Declared
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...
206
                            $defAllianceID = trim(explode(": ", $notificationString[0])[1]);
207
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
208
                            $defAllianceName = apiCharacterName($defAllianceID);
209
                            $aggAllianceName = apiCharacterName($aggAllianceID);
210
                            $msg = "@everyone | War declared by {$aggAllianceName} against {$defAllianceName}. Fighting begins in roughly 24 hours.";
211
                            break;
212
                        case 6: // Corp joins war (Not enough info in api to say who the 3rd party is)
213
                            $defAllianceID = trim(explode(": ", $notificationString[0])[1]);
214
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
215
                            $defAllianceName = apiCharacterName($defAllianceID);
216
                            $aggAllianceName = apiCharacterName($aggAllianceID);
217
                            $msg = "The war between {$aggAllianceName} and {$defAllianceName} has been joined by a third party. This new group may begin fighting in roughly 24 hours.";
218
                            break;
219 View Code Duplication
                        case 7: // War Declared corp
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...
220
                            $defCorpID = trim(explode(": ", $notificationString[0])[1]);
221
                            $aggCorpID = trim(explode(": ", $notificationString[2])[1]);
222
                            $defCorpName = apiCharacterName($defCorpID);
223
                            $aggCorpName = apiCharacterName($aggCorpID);
224
                            $msg = "@everyone | War declared by {$aggCorpName} against {$defCorpName}. Fighting begins in roughly 24 hours.";
225
                            break;
226 View Code Duplication
                        case 8: // Alliance war invalidated by CONCORD
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...
227
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
228
                            $aggAllianceName = apiCharacterName($aggAllianceID);
229
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
230
                            break;
231
                        case 9: // Pilot bill
232
                            $msg = "skip";
233
                            break;
234
                        case 10: // Bill issued
235
                            $msg = "skip";
236
                            break;
237
                        case 11: // Bill stuff
238
                            $msg = "skip";
239
                            break;
240
                        case 12: // Bill Stuff
241
                            $msg = "skip";
242
                            break;
243
                        case 13: // Bill issued
244
                            $msg = "skip";
245
                            break;
246
                        case 14: // Bounty payment
247
                            $msg = "skip";
248
                            break;
249
                        case 16: // Mail
250
                            $msg = "skip";
251
                            break;
252
                        case 17: // Corp app
253
                            $msg = "skip";
254
                            break;
255
                        case 18: // Corp app
256
                            $msg = "skip";
257
                            break;
258
                        case 19: // corp tax changed
259
                            $corpID = trim(explode(": ", $notificationString[0])[1]);
260
                            $corpName = apiCharacterName($corpID);
261
                            $oldTax = trim(explode(": ", $notificationString[2])[1]);
262
                            $newTax = trim(explode(": ", $notificationString[1])[1]);
263
                            $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%";
264
                            if ($this->allianceOnly == "true") {
265
                                $msg = "skip";
266
                            }
267
                            break;
268
                        case 20: // Corp news?
269
                            $msg = "skip";
270
                            break;
271
                        case 21: // member left corp
272
                            $msg = "skip";
273
                            break;
274 View Code Duplication
                        case 31: // Alliance war invalidated by CONCORD
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...
275
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
276
                            $aggAllianceName = apiCharacterName($aggAllianceID);
277
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
278
                            break;
279
                        case 34: // Noob ship
280
                            $msg = "skip";
281
                            break;
282
                        case 35: // Insurance payment
283
                            $msg = "skip";
284
                            break;
285 View Code Duplication
                        case 41: // System lost
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...
286
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
287
                            $systemName = apiCharacterName($solarSystemID);
288
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
289
                            $allianceName = apiCharacterName($allianceID);
290
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
291
                            break;
292 View Code Duplication
                        case 43: // System captured
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...
293
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
294
                            $systemName = apiCharacterName($solarSystemID);
295
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
296
                            $allianceName = apiCharacterName($allianceID);
297
                            $msg = "{$allianceName} now controls **{$systemName}**";
298
                            break;
299
                        case 45: // Tower anchoring
300
                            $msg = "skip";
301
                            break;
302
                        case 52: // clone revoked
303
                            $msg = "skip";
304
                            break;
305
                        case 54: // insurance
306
                            $msg = "skip";
307
                            break;
308
                        case 57: // jump clone destruction
309
                            $msg = "skip";
310
                            break;
311
                        case 71: // Mission Expiration
312
                            $msg = "skip";
313
                            break;
314
                        case 75: // POS / POS Module under attack
315
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
316
                            $aggAllianceName = apiCharacterName($aggAllianceID);
317
                            $aggCorpID = trim(explode(": ", $notificationString[1])[1]);
318
                            $aggCorpName = apiCharacterName($aggCorpID);
319
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
320
                            $aggCharacterName = apiCharacterName($aggID);
321
                            $moonID = trim(explode(": ", $notificationString[5])[1]);
322
                            $moonName = apiCharacterName($moonID);
323
                            $solarSystemID = trim(explode(": ", $notificationString[7])[1]);
324
                            $typeID = trim(explode(": ", $notificationString[8])[1]);
325
                            $typeName = apiTypeName($typeID);
326
                            $systemName = apiCharacterName($solarSystemID);
327
                            $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}).";
328
                            if ($this->allianceOnly == "true") {
329
                                $msg = "skip";
330
                            }
331
                            break;
332
                        case 76: // Tower resource alert
333
                            $moonID = trim(explode(": ", $notificationString[2])[1]);
334
                            $moonName = apiCharacterName($moonID);
335
                            $solarSystemID = trim(explode(": ", $notificationString[3])[1]);
336
                            $systemName = apiCharacterName($solarSystemID);
337
                            $blocksRemaining = trim(explode(": ", $notificationString[6])[1]);
338
                            $typeID = trim(explode(": ", $notificationString[7])[1]);
339
                            $channelID = $this->fuelChannel;
340
                            $typeName = apiTypeName($typeID);
341
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
342
                            if ($this->fuelSkip == "true" || $this->allianceOnly == "true") {
343
                                $msg = "skip";
344
                            }
345
346
                            break;
347
                        case 88: // IHUB is being attacked
348
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
349
                            $aggAllianceName = apiCharacterName($aggAllianceID);
350
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
351
                            $aggCorpName = apiCharacterName($aggCorpID);
352
                            $aggID = trim(explode(": ", $notificationString[1])[1]);
353
                            $aggCharacterName = apiCharacterName($aggID);
354
                            $armorValue = trim(explode(": ", $notificationString[3])[1]);
355
                            $hullValue = trim(explode(": ", $notificationString[4])[1]);
356
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
357
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
358
                            $systemName = apiCharacterName($solarSystemID);
359
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
360
                            break;
361
                        case 93: // Customs office is being attacked
362
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
363
                            $aggAllianceName = apiCharacterName($aggAllianceID);
364
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
365
                            $aggCorpName = apiCharacterName($aggCorpID);
366
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
367
                            $aggCharacterName = apiCharacterName($aggID);
368
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
369
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
370
                            $systemName = apiCharacterName($solarSystemID);
371
                            $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
372
                            if ($this->allianceOnly == "true") {
373
                                $msg = "skip";
374
                            }
375
                            break;
376
                        case 94: // POCO Reinforced
377
                            $msg = "Customs Office reinforced.";
378
                            break;
379
                        case 95: // IHub Transfer
380
                            $msg = "skip";
381
                            break;
382 View Code Duplication
                        case 100: // Aggressor corp joins war
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...
383
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
384
                            $defCorpID = trim(explode(": ", $notificationString[1])[1]);
385
                            $aggCorpName = apiCharacterName($aggCorpID);
386
                            $defCorpName = apiCharacterName($defCorpID);
387
                            $msg = "{$aggCorpName} has joined the war against {$defCorpName}.";
388
                            break;
389
                        case 102: // War support offer? I think?
390
                            $msg = "skip";
391
                            break;
392
                        case 103: // War support offer? I think?
393
                            $msg = "skip";
394
                            break;
395
                        case 111: // Bounty
396
                            $msg = "skip";
397
                            break;
398
                        case 128: // Corp App
399
                            $msg = "skip";
400
                            break;
401
                        case 129: // App denied
402
                            $msg = "skip";
403
                            break;
404
                        case 130: // Corp app withdrawn?
405
                            $msg = "skip";
406
                            break;
407
                        case 135: // ESS stolen
408
                            $msg = "skip";
409
                            break;
410
                        case 138: // Clone activation
411
                            $msg = "skip";
412
                            break;
413
                        case 140: // Kill report
414
                            $msg = "skip";
415
                            break;
416
                        case 141: // Kill report
417
                            $msg = "skip";
418
                            break;
419 View Code Duplication
                        case 147: // Entosis has started
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...
420
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
421
                            $systemName = apiCharacterName($solarSystemID);
422
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
423
                            $typeName = apiTypeName($typeID);
424
                            $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
425
                            break;
426 View Code Duplication
                        case 148: // Entosis enabled a module ??????
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...
427
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
428
                            $systemName = apiCharacterName($solarSystemID);
429
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
430
                            $typeName = apiTypeName($typeID);
431
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
432
                            break;
433 View Code Duplication
                        case 149: // Entosis disabled a module
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...
434
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
435
                            $systemName = apiCharacterName($solarSystemID);
436
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
437
                            $typeName = apiTypeName($typeID);
438
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
439
                            break;
440
                        case 152: // Sov bill
441
                            $msg = "skip";
442
                            break;
443 View Code Duplication
                        case 160: // Entosis successful
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...
444
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
445
                            $systemName = apiCharacterName($solarSystemID);
446
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
447
                            break;
448 View Code Duplication
                        case 161: //  Command Nodes Decloaking
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...
449
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
450
                            $systemName = apiCharacterName($solarSystemID);
451
                            $msg = "Command nodes decloaking for **{$systemName}**";
452
                            break;
453 View Code Duplication
                        case 162: //  TCU Destroyed
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...
454
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
455
                            $systemName = apiCharacterName($solarSystemID);
456
                            $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed.";
457
                            break;
458 View Code Duplication
                        case 163: //  Outpost freeport
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...
459
                            $solarSystemID = trim(explode(": ", $notificationString[1])[1]);
460
                            $systemName = apiCharacterName($solarSystemID);
461
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
462
                            break;
463 View Code Duplication
                        case 182: //  Citadel being anchored
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...
464
                            $corpName = trim(explode(": ", $notificationString[1])[1]);
465
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
466
                            $systemName = apiCharacterName($solarSystemID);
467
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
468
                            break;
469
                        case 184: //  Citadel under attack
470
                            $aggID = trim(explode(": ", $notificationString[7])[1]);
471
                            $aggCharacterName = apiCharacterName($aggID);
472
                            $solarSystemID = trim(explode(": ", $notificationString[15])[1]);
473
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
474
                            $aggAllianceName = apiCharacterName($aggAllianceID);
475
                            $aggCorpID = trim(explode("- ", $notificationString[11])[1]);
476
                            $aggCorpName = apiCharacterName($aggCorpID);
477
                            $systemName = apiCharacterName($solarSystemID);
478
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
479
                            break;
480 View Code Duplication
                        case 185: //  Citadel online
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...
481
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
482
                            $systemName = apiCharacterName($solarSystemID);
483
                            $msg = "Citadel now online in **{$systemName}**.";
484
                            break;
485 View Code Duplication
                        case 188: //  Citadel destroyed
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...
486
                            $corpID = trim(explode("- ", $notificationString[3])[1]);
487
                            $corpName = apiCharacterName($corpID);
488
                            $solarSystemID = trim(explode(": ", $notificationString[5])[1]);
489
                            $systemName = apiCharacterName($solarSystemID);
490
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
491
                            break;
492
                        case 199: // citadel delivery
493
                            $msg = "skip";
494
                            break;
495
                        default: // Unknown typeID
496
                            $string = implode(" ", $notificationString);
497
                            $msg = "typeID {$typeID} is an unmapped notification, please create a Github issue with this entire message and please include what the in-game notification is. {$string}";
498
                            break;
499
                    }
500
501
                    if ($msg == "skip") {
502
                        return null;
503
                    }
504
                    $this->logger->addInfo("Notifications: Notification queued, Message - {$msg}");
505
                    priorityQueueMessage($msg, $channelID, $this->guild);
506
                    // Find the maxID so we don't output this message again in the future
507
                    $this->maxID = max($notificationID, $this->maxID);
508
                    $this->newestNotificationID = $this->maxID;
509
                    setPermCache("newestNotificationID", $this->maxID);
510
                }
511
            }
512
513
            $this->logger->addInfo("Notifications: Next Notification Check At: {$cacheTimer} EVE Time");
514
        } catch (Exception $e) {
515
            $this->logger->addInfo("Notifications: Notification Error: " . $e->getMessage());
516
        }
517
        return null;
518
    }
519
520
    /**
521
     * @param $keyID
522
     * @param $vCode
523
     * @param $characterID
524
     * @param $notificationID
525
     * @return string
526
     */
527
    function getNotificationText($keyID, $vCode, $characterID, $notificationID)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
528
    {
529
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
530
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
531
            "SimpleXMLElement", LIBXML_NOCDATA)), true);
532
        $data = $data["result"]["rowset"]["row"];
533
        return $data;
534
    }
535
536
    /**
537
     *
538
     */
539
    function onMessage()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
540
    {
541
    }
542
543
544
    /**
545
     * @return array
546
     */
547
    function information()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
548
    {
549
        return array(
550
            "name" => "",
551
            "trigger" => array(""),
552
            "information" => "");
553
    }
554
}
555