Test Setup Failed
Push — master ( fec420...86fb9b )
by Bob
06:30 queued 03:13
created

notifications::apiData()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 4
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
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
 */
34
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...
35
{
36
    /**
37
     * @var
38
     */
39
    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...
40
    /**
41
     * @var
42
     */
43
    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...
44
    /**
45
     * @var
46
     */
47
    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...
48
    /**
49
     * @var
50
     */
51
    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...
52
    /**
53
     * @var
54
     */
55
    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...
56
    /**
57
     * @var
58
     */
59
    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...
60
    /**
61
     * @var
62
     */
63
    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...
64
    /**
65
     * @var
66
     */
67
    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...
68
    /**
69
     * @var
70
     */
71
    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...
72
    /**
73
     * @var
74
     */
75
    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...
76
    /**
77
     * @var
78
     */
79
    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...
80
    /**
81
     * @var
82
     */
83
    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...
84
    public $fuelChannel;
85
    public $fuelSkip;
86
    public $keyID;
87
    public $vCode;
88
    public $characterID;
89
    public $guild;
90
91
    /**
92
     * @param $config
93
     * @param $discord
94
     * @param $logger
95
     */
96
    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...
97
    {
98
        $this->config = $config;
99
        $this->discord = $discord;
100
        $this->logger = $logger;
101
        $this->toDiscordChannel = $config["plugins"]["notifications"]["channelID"];
102
        $this->fuelChannel = $config["plugins"]["fuel"]["channelID"];
103
        $this->fuelSkip = $config["plugins"]["fuel"]["skip"];
104
        $this->newestNotificationID = getPermCache("newestNotificationID");
105
        $this->maxID = 0;
106
        $this->keyID = $config["eve"]["apiKeys"]["user1"]["keyID"];
107
        $this->vCode = $config["eve"]["apiKeys"]["user1"]["vCode"];
108
        $this->characterID = $config["eve"]["apiKeys"]["user1"]["characterID"];
109
        $this->guild = $config["bot"]["guild"];
110
        $lastCheck = getPermCache("notificationsLastChecked{$this->keyID}");
111
        if ($lastCheck == NULL) {
112
            // Schedule it for right now if first run
113
            setPermCache("notificationsLastChecked{$this->keyID}", time() - 5);
114
        }
115
    }
116
    /**
117
     *
118
     */
119 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...
120
    {
121
        $lastChecked = getPermCache("notificationsLastChecked{$this->keyID}");
122
        $keyID = $this->keyID;
123
        $vCode = $this->vCode;
124
        $characterID = $this->characterID;
125
126
        if ($lastChecked <= time()) {
127
            $this->logger->addInfo("Checking API Key {$keyID} for notifications..");
128
            $this->getNotifications($keyID, $vCode, $characterID);
129
        }
130
131
    }
132
133
    /**
134
     * @param $keyID
135
     * @param $vCode
136
     * @param $characterID
137
     * @return null
138
     */
139
    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...
140
    {
141
        $discord = $this->discord;
142
143
        try {
144
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
145
            $xml = makeApiRequest($url);
146
            date_default_timezone_set('UTC');
147
            $cached = $xml->cachedUntil[0];
148
            $baseUnix = strtotime($cached);
149
            $cacheClr = $baseUnix - 13500;
150
            if (!isset($this->fuelChannel)) {
151
                $this->fuelChannel = $this->toDiscordChannel;
152
            }
153 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...
154
                $weirdTime = time() + 1830;
155
                $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime);
156
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
157
            } else {
158
                $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr);
159
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
160
            }
161
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
162
                "SimpleXMLElement", LIBXML_NOCDATA)), true);
163
            $data = $data["result"]["rowset"]["row"];
164
            // If there is no data, just quit..
165
            if (empty($data)) {
166
                return;
167
            }
168
            $fixedData = array();
169
            // Sometimes there is only ONE notification, so.. yeah..
170
            if (isset($data["@attributes"])) { $fixedData[] = $data["@attributes"]; }
171
            if (count($data) > 1) {
172
                foreach ($data as $multiNotif) {
173
                    $fixedData[] = $multiNotif["@attributes"];
174
                }
175
            }
176
            foreach ($fixedData as $notification) {
177
                $notificationID = $notification["notificationID"];
178
                $typeID = $notification["typeID"];
179
                $sentDate = $notification["sentDate"];
180
                $channelID = $this->toDiscordChannel;
181
                if ($notificationID > $this->newestNotificationID) {
182
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID,
183
                        $notificationID));
184
                    switch ($typeID) {
185 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...
186
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
187
                            $aggAllianceName = apiCharacterName($aggAllianceID);
188
                            $msg = "@everyone | War declared by {$aggAllianceName}. Fighting begins in roughly 24 hours.";
189
                            break;
190 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...
191
                            $aggCorpID = trim(explode(": ", $notificationString[2])[1]);
192
                            $aggCorpName = apiCharacterName($aggCorpID);
193
                            $msg = "@everyone | War declared by {$aggCorpName}. Fighting begins in roughly 24 hours.";
194
                            break;
195 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...
196
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
197
                            $aggAllianceName = apiCharacterName($aggAllianceID);
198
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
199
                            break;
200
                        case 10: // Bill issued
201
                            $msg = "skip";
202
                            break;
203
                        case 13: // Bill issued
204
                            $msg = "skip";
205
                            break;
206
                        case 14: // Bounty payment
207
                            $msg = "skip";
208
                            break;
209
                        case 16: // Mail
210
                            $msg = "skip";
211
                            break;
212
                        case 19: // corp tax changed
213
                            $corpID = trim(explode(": ", $notificationString[0])[1]);
214
                            $corpName = apiCharacterName($corpID);
215
                            $oldTax = trim(explode(": ", $notificationString[2])[1]);
216
                            $newTax = trim(explode(": ", $notificationString[1])[1]);
217
                            $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%";
218
                            break;
219
                        case 21: // member left corp
220
                            $msg = "skip";
221
                            break;
222 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...
223
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
224
                            $aggAllianceName = apiCharacterName($aggAllianceID);
225
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
226
                            break;
227
                        case 35: // Insurance payment
228
                            $msg = "skip";
229
                            break;
230 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...
231
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
232
                            $systemName = apiCharacterName($solarSystemID);
233
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
234
                            $allianceName = apiCharacterName($allianceID);
235
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
236
                            break;
237 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...
238
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
239
                            $systemName = apiCharacterName($solarSystemID);
240
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
241
                            $allianceName = apiCharacterName($allianceID);
242
                            $msg = "{$allianceName} now controls **{$systemName}**";
243
                            break;
244
                        case 52: // clone revoked
245
                            $msg = "skip";
246
                            break;
247
                        case 54: // insurance
248
                            $msg = "skip";
249
                            break;
250
                        case 57: // jump clone destruction
251
                            $msg = "skip";
252
                            break;
253
                        case 71: // Mission Expiration
254
                            $msg = "skip";
255
                            break;
256
                        case 75: // POS / POS Module under attack
257
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
258
                            $aggAllianceName = apiCharacterName($aggAllianceID);
259
                            $aggCorpID = trim(explode(": ", $notificationString[1])[1]);
260
                            $aggCorpName = apiCharacterName($aggCorpID);
261
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
262
                            $aggCharacterName = apiCharacterName($aggID);
263
                            $moonID = trim(explode(": ", $notificationString[5])[1]);
264
                            $moonName = apiCharacterName($moonID);
265
                            $solarSystemID = trim(explode(": ", $notificationString[7])[1]);
266
                            $typeID = trim(explode(": ", $notificationString[8])[1]);
267
                            $typeName = apiTypeName($typeID);
268
                            $systemName = apiCharacterName($solarSystemID);
269
                            $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}).";
270
                            break;
271
                        case 76: // Tower resource alert
272
                            $moonID = trim(explode(": ", $notificationString[2])[1]);
273
                            $moonName = apiCharacterName($moonID);
274
                            $solarSystemID = trim(explode(": ", $notificationString[3])[1]);
275
                            $systemName = apiCharacterName($solarSystemID);
276
                            $blocksRemaining = trim(explode(": ", $notificationString[6])[1]);
277
                            $typeID = trim(explode(": ", $notificationString[7])[1]);
278
                            $channelID = $this->fuelChannel;
279
                            $typeName = apiTypeName($typeID);
280
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
281
                            if ($this->fuelSkip != "false") {
282
                                $msg = "skip";
283
                            }
284
285
                            break;
286
                        case 88: // IHUB is being attacked
287
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
288
                            $aggAllianceName = apiCharacterName($aggAllianceID);
289
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
290
                            $aggCorpName = apiCharacterName($aggCorpID);
291
                            $aggID = trim(explode(": ", $notificationString[1])[1]);
292
                            $aggCharacterName = apiCharacterName($aggID);
293
                            $armorValue = trim(explode(": ", $notificationString[3])[1]);
294
                            $hullValue = trim(explode(": ", $notificationString[4])[1]);
295
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
296
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
297
                            $systemName = apiCharacterName($solarSystemID);
298
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
299
                            break;
300
                        case 93: // Customs office is being attacked
301
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
302
                            $aggAllianceName = apiCharacterName($aggAllianceID);
303
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
304
                            $aggCorpName = apiCharacterName($aggCorpID);
305
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
306
                            $aggCharacterName = apiCharacterName($aggID);
307
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
308
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
309
                            $systemName = apiCharacterName($solarSystemID);
310
                            $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
311
                            break;
312
                        case 94: // POCO Reinforced
313
                            $msg = "Customs Office reinforced.";
314
                            break;
315
                        case 95: // IHub Transfer
316
                            $msg = "skip";
317
                            break;
318
                        case 102: // War support offer? I think?
319
                            $msg = "skip";
320
                            break;
321
                        case 103: // War support offer? I think?
322
                            $msg = "skip";
323
                            break;
324
                        case 111: // Bounty
325
                            $msg = "skip";
326
                            break;
327
                        case 128: // Corp App
328
                            $msg = "skip";
329
                            break;
330
                        case 129: // App denied
331
                            $msg = "skip";
332
                            break;
333
                        case 130: // Corp app withdrawn?
334
                            $msg = "skip";
335
                            break;
336
                        case 138: // Clone activation
337
                            $msg = "skip";
338
                            break;
339
                        case 140: // Kill report
340
                            $msg = "skip";
341
                            break;
342
                        case 141: // Kill report
343
                            $msg = "skip";
344
                            break;
345 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...
346
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
347
                            $systemName = apiCharacterName($solarSystemID);
348
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
349
                            $typeName = apiTypeName($typeID);
350
                            $msg = "Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
351
                            break;
352 View Code Duplication
                        case 148: // Entosis enabled a module ??????
1 ignored issue
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...
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
353
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
354
                            $systemName = apiCharacterName($solarSystemID);
355
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
356
                            $typeName = apiTypeName($typeID);
357
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
358
                            break;
359 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...
360
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
361
                            $systemName = apiCharacterName($solarSystemID);
362
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
363
                            $typeName = apiTypeName($typeID);
364
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
365
                            break;
366 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...
367
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
368
                            $systemName = apiCharacterName($solarSystemID);
369
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
370
                            break;
371 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...
372
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
373
                            $systemName = apiCharacterName($solarSystemID);
374
                            $msg = "Command nodes decloaking for **{$systemName}**";
375
                            break;
376 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...
377
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
378
                            $systemName = apiCharacterName($solarSystemID);
379
                            $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed.";
380
                            break;
381 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...
382
                            $solarSystemID = trim(explode(": ", $notificationString[1])[1]);
383
                            $systemName = apiCharacterName($solarSystemID);
384
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
385
                            break;
386 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...
387
                            $corpName = trim(explode(": ", $notificationString[1])[1]);
388
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
389
                            $systemName = apiCharacterName($solarSystemID);
390
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
391
                            break;
392
                        case 184: //  Citadel under attack
393
                            $aggID = trim(explode(": ", $notificationString[7])[1]);
394
                            $aggCharacterName = apiCharacterName($aggID);
395
                            $solarSystemID = trim(explode(": ", $notificationString[15])[1]);
396
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
397
                            $aggAllianceName = apiCharacterName($aggAllianceID);
398
                            $aggCorpID = trim(explode("- ", $notificationString[11])[1]);
399
                            $aggCorpName = apiCharacterName($aggCorpID);
400
                            $systemName = apiCharacterName($solarSystemID);
401
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
402
                            break;
403 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...
404
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
405
                            $systemName = apiCharacterName($solarSystemID);
406
                            $msg = "Citadel now online in **{$systemName}**.";
407
                            break;
408 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...
409
                            $corpID = trim(explode("- ", $notificationString[3])[1]);
410
                            $corpName = apiCharacterName($corpID);
411
                            $solarSystemID = trim(explode(": ", $notificationString[5])[1]);
412
                            $systemName = apiCharacterName($solarSystemID);
413
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
414
                            break;
415
                        case 199: // citadel delivery
416
                            $msg = "skip";
417
                            break;
418
                        default: // Unknown typeID
419
                            $string = implode(" ", $notificationString);
420
                            $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}";
421
                            break;
422
                    }
423
424
                    if ($msg == "skip") {
425
                        return null;
426
                    }
427
                    $this->logger->addInfo("Notification sent to channel {$this->toDiscordChannel}, Message - {$msg}");
428
                    $guild = $discord->guilds->get('id', $this->guild);
429
                    $channel = $guild->channels->get('id', $channelID);
430
                    $channel->sendMessage($msg, false);
431
                    // Find the maxID so we don't output this message again in the future
432
                    $this->maxID = max($notificationID, $this->maxID);
433
                    $this->newestNotificationID = $this->maxID;
434
                    setPermCache("newestNotificationID", $this->maxID);
435
                }
436
            }
437
438
            $this->logger->addInfo("Next Notification Check At: {$cacheTimer} EVE Time");
439
        } catch (Exception $e) {
440
            $this->logger->addInfo("Notification Error: " . $e->getMessage());
441
        }
442
        return null;
443
    }
444
    /**
445
     * @param $keyID
446
     * @param $vCode
447
     * @param $characterID
448
     * @param $notificationID
449
     * @return string
450
     */
451
    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...
452
    {
453
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
454
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
455
            "SimpleXMLElement", LIBXML_NOCDATA)), true);
456
        $data = $data["result"]["rowset"]["row"];
457
        return $data;
458
    }
459
    /**
460
     *
461
     */
462
    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...
463
    {
464
    }
465
466
467
    /**
468
     * @return array
469
     */
470
    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...
471
    {
472
        return array(
473
            "name" => "",
474
            "trigger" => array(""),
475
            "information" => "");
476
    }
477
}
478