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

notifications::init()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 19
nc 4
nop 3
dl 0
loc 24
rs 8.9713
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
 * @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
        $lastCheck = getPermCache("notificationsLastChecked{$this->keyID}");
113
        if ($lastCheck == NULL) {
114
            // Schedule it for right now if first run
115
            setPermCache("notificationsLastChecked{$this->keyID}", time() - 5);
116
        }
117
        if (is_null($this->allianceOnly)){
118
            $this->allianceOnly = "false";
119
        }
120
    }
121
    /**
122
     *
123
     */
124 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...
125
    {
126
        $lastChecked = getPermCache("notificationsLastChecked{$this->keyID}");
127
        $keyID = $this->keyID;
128
        $vCode = $this->vCode;
129
        $characterID = $this->characterID;
130
131
        if ($lastChecked <= time()) {
132
            $this->logger->addInfo("Checking API Key {$keyID} for notifications..");
133
            $this->getNotifications($keyID, $vCode, $characterID);
134
        }
135
136
    }
137
138
    /**
139
     * @param $keyID
140
     * @param $vCode
141
     * @param $characterID
142
     * @return null
143
     */
144
    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...
145
    {
146
        $discord = $this->discord;
147
148
        try {
149
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
150
            $xml = makeApiRequest($url);
151
            date_default_timezone_set('UTC');
152
            $cached = $xml->cachedUntil[0];
153
            $baseUnix = strtotime($cached);
154
            $cacheClr = $baseUnix - 13500;
155
            if (!isset($this->fuelChannel)) {
156
                $this->fuelChannel = $this->toDiscordChannel;
157
            }
158 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...
159
                $weirdTime = time() + 1830;
160
                $cacheTimer = gmdate("Y-m-d H:i:s", $weirdTime);
161
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
162
            } else {
163
                $cacheTimer = gmdate("Y-m-d H:i:s", $cacheClr);
164
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
165
            }
166
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
167
                "SimpleXMLElement", LIBXML_NOCDATA)), true);
168
            $data = $data["result"]["rowset"]["row"];
169
            // If there is no data, just quit..
170
            if (empty($data)) {
171
                return;
172
            }
173
            $fixedData = array();
174
            // Sometimes there is only ONE notification, so.. yeah..
175
            if (isset($data["@attributes"])) { $fixedData[] = $data["@attributes"]; }
176
            if (count($data) > 1) {
177
                foreach ($data as $multiNotif) {
178
                    $fixedData[] = $multiNotif["@attributes"];
179
                }
180
            }
181
            foreach ($fixedData as $notification) {
182
                $notificationID = $notification["notificationID"];
183
                $typeID = $notification["typeID"];
184
                $sentDate = $notification["sentDate"];
185
                $channelID = $this->toDiscordChannel;
186
                if ($notificationID > $this->newestNotificationID) {
187
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID,
188
                        $notificationID));
189
                    switch ($typeID) {
190 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...
191
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
192
                            $aggAllianceName = apiCharacterName($aggAllianceID);
193
                            $msg = "@everyone | War declared by {$aggAllianceName}. Fighting begins in roughly 24 hours.";
194
                            break;
195 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...
196
                            $aggCorpID = trim(explode(": ", $notificationString[2])[1]);
197
                            $aggCorpName = apiCharacterName($aggCorpID);
198
                            $msg = "@everyone | War declared by {$aggCorpName}. Fighting begins in roughly 24 hours.";
199
                            break;
200 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...
201
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
202
                            $aggAllianceName = apiCharacterName($aggAllianceID);
203
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
204
                            break;
205
                        case 10: // Bill issued
206
                            $msg = "skip";
207
                            break;
208
                        case 13: // Bill issued
209
                            $msg = "skip";
210
                            break;
211
                        case 14: // Bounty payment
212
                            $msg = "skip";
213
                            break;
214
                        case 16: // Mail
215
                            $msg = "skip";
216
                            break;
217
                        case 19: // corp tax changed
218
                            $corpID = trim(explode(": ", $notificationString[0])[1]);
219
                            $corpName = apiCharacterName($corpID);
220
                            $oldTax = trim(explode(": ", $notificationString[2])[1]);
221
                            $newTax = trim(explode(": ", $notificationString[1])[1]);
222
                            $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%";
223
                            if ($this->allianceOnly == "true") {
224
                                $msg = "skip";
225
                            }
226
                            break;
227
                        case 21: // member left corp
228
                            $msg = "skip";
229
                            break;
230 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...
231
                            $aggAllianceID = trim(explode(": ", $notificationString[2])[1]);
232
                            $aggAllianceName = apiCharacterName($aggAllianceID);
233
                            $msg = "War with {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
234
                            break;
235
                        case 35: // Insurance payment
236
                            $msg = "skip";
237
                            break;
238 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...
239
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
240
                            $systemName = apiCharacterName($solarSystemID);
241
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
242
                            $allianceName = apiCharacterName($allianceID);
243
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
244
                            break;
245 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...
246
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
247
                            $systemName = apiCharacterName($solarSystemID);
248
                            $allianceID = trim(explode(": ", $notificationString[0])[1]);
249
                            $allianceName = apiCharacterName($allianceID);
250
                            $msg = "{$allianceName} now controls **{$systemName}**";
251
                            break;
252
                        case 52: // clone revoked
253
                            $msg = "skip";
254
                            break;
255
                        case 54: // insurance
256
                            $msg = "skip";
257
                            break;
258
                        case 57: // jump clone destruction
259
                            $msg = "skip";
260
                            break;
261
                        case 71: // Mission Expiration
262
                            $msg = "skip";
263
                            break;
264
                        case 75: // POS / POS Module under attack
265
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
266
                            $aggAllianceName = apiCharacterName($aggAllianceID);
267
                            $aggCorpID = trim(explode(": ", $notificationString[1])[1]);
268
                            $aggCorpName = apiCharacterName($aggCorpID);
269
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
270
                            $aggCharacterName = apiCharacterName($aggID);
271
                            $moonID = trim(explode(": ", $notificationString[5])[1]);
272
                            $moonName = apiCharacterName($moonID);
273
                            $solarSystemID = trim(explode(": ", $notificationString[7])[1]);
274
                            $typeID = trim(explode(": ", $notificationString[8])[1]);
275
                            $typeName = apiTypeName($typeID);
276
                            $systemName = apiCharacterName($solarSystemID);
277
                            $msg = "**{$typeName}** under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}).";
278
                            if ($this->allianceOnly == "true") {
279
                                $msg = "skip";
280
                            }
281
                            break;
282
                        case 76: // Tower resource alert
283
                            $moonID = trim(explode(": ", $notificationString[2])[1]);
284
                            $moonName = apiCharacterName($moonID);
285
                            $solarSystemID = trim(explode(": ", $notificationString[3])[1]);
286
                            $systemName = apiCharacterName($solarSystemID);
287
                            $blocksRemaining = trim(explode(": ", $notificationString[6])[1]);
288
                            $typeID = trim(explode(": ", $notificationString[7])[1]);
289
                            $channelID = $this->fuelChannel;
290
                            $typeName = apiTypeName($typeID);
291
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
292
                            if ($this->fuelSkip == "true" || $this->allianceOnly == "true") {
293
                                $msg = "skip";
294
                            }
295
296
                            break;
297
                        case 88: // IHUB is being attacked
298
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
299
                            $aggAllianceName = apiCharacterName($aggAllianceID);
300
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
301
                            $aggCorpName = apiCharacterName($aggCorpID);
302
                            $aggID = trim(explode(": ", $notificationString[1])[1]);
303
                            $aggCharacterName = apiCharacterName($aggID);
304
                            $armorValue = trim(explode(": ", $notificationString[3])[1]);
305
                            $hullValue = trim(explode(": ", $notificationString[4])[1]);
306
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
307
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
308
                            $systemName = apiCharacterName($solarSystemID);
309
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
310
                            break;
311
                        case 93: // Customs office is being attacked
312
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
313
                            $aggAllianceName = apiCharacterName($aggAllianceID);
314
                            $aggCorpID = trim(explode(": ", $notificationString[0])[1]);
315
                            $aggCorpName = apiCharacterName($aggCorpID);
316
                            $aggID = trim(explode(": ", $notificationString[2])[1]);
317
                            $aggCharacterName = apiCharacterName($aggID);
318
                            $shieldValue = trim(explode(": ", $notificationString[5])[1]);
319
                            $solarSystemID = trim(explode(": ", $notificationString[6])[1]);
320
                            $systemName = apiCharacterName($solarSystemID);
321
                            $msg = "Customs Office under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
322
                            if ($this->allianceOnly == "true") {
323
                                $msg = "skip";
324
                            }
325
                            break;
326
                        case 94: // POCO Reinforced
327
                            $msg = "Customs Office reinforced.";
328
                            break;
329
                        case 95: // IHub Transfer
330
                            $msg = "skip";
331
                            break;
332
                        case 102: // War support offer? I think?
333
                            $msg = "skip";
334
                            break;
335
                        case 103: // War support offer? I think?
336
                            $msg = "skip";
337
                            break;
338
                        case 111: // Bounty
339
                            $msg = "skip";
340
                            break;
341
                        case 128: // Corp App
342
                            $msg = "skip";
343
                            break;
344
                        case 129: // App denied
345
                            $msg = "skip";
346
                            break;
347
                        case 130: // Corp app withdrawn?
348
                            $msg = "skip";
349
                            break;
350
                        case 138: // Clone activation
351
                            $msg = "skip";
352
                            break;
353
                        case 140: // Kill report
354
                            $msg = "skip";
355
                            break;
356
                        case 141: // Kill report
357
                            $msg = "skip";
358
                            break;
359 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...
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 started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
365
                            break;
366 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...
367
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
368
                            $systemName = apiCharacterName($solarSystemID);
369
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
370
                            $typeName = apiTypeName($typeID);
371
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
372
                            break;
373 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...
374
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
375
                            $systemName = apiCharacterName($solarSystemID);
376
                            $typeID = trim(explode(": ", $notificationString[1])[1]);
377
                            $typeName = apiTypeName($typeID);
378
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
379
                            break;
380 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...
381
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
382
                            $systemName = apiCharacterName($solarSystemID);
383
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
384
                            break;
385 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...
386
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
387
                            $systemName = apiCharacterName($solarSystemID);
388
                            $msg = "Command nodes decloaking for **{$systemName}**";
389
                            break;
390 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...
391
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
392
                            $systemName = apiCharacterName($solarSystemID);
393
                            $msg = "Entosis successful, TCU in **{$systemName}** has been destroyed.";
394
                            break;
395 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...
396
                            $solarSystemID = trim(explode(": ", $notificationString[1])[1]);
397
                            $systemName = apiCharacterName($solarSystemID);
398
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
399
                            break;
400 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...
401
                            $corpName = trim(explode(": ", $notificationString[1])[1]);
402
                            $solarSystemID = trim(explode(": ", $notificationString[2])[1]);
403
                            $systemName = apiCharacterName($solarSystemID);
404
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
405
                            break;
406
                        case 184: //  Citadel under attack
407
                            $aggID = trim(explode(": ", $notificationString[7])[1]);
408
                            $aggCharacterName = apiCharacterName($aggID);
409
                            $solarSystemID = trim(explode(": ", $notificationString[15])[1]);
410
                            $aggAllianceID = trim(explode(": ", $notificationString[0])[1]);
411
                            $aggAllianceName = apiCharacterName($aggAllianceID);
412
                            $aggCorpID = trim(explode("- ", $notificationString[11])[1]);
413
                            $aggCorpName = apiCharacterName($aggCorpID);
414
                            $systemName = apiCharacterName($solarSystemID);
415
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
416
                            break;
417 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...
418
                            $solarSystemID = trim(explode(": ", $notificationString[0])[1]);
419
                            $systemName = apiCharacterName($solarSystemID);
420
                            $msg = "Citadel now online in **{$systemName}**.";
421
                            break;
422 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...
423
                            $corpID = trim(explode("- ", $notificationString[3])[1]);
424
                            $corpName = apiCharacterName($corpID);
425
                            $solarSystemID = trim(explode(": ", $notificationString[5])[1]);
426
                            $systemName = apiCharacterName($solarSystemID);
427
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
428
                            break;
429
                        case 199: // citadel delivery
430
                            $msg = "skip";
431
                            break;
432
                        default: // Unknown typeID
433
                            $string = implode(" ", $notificationString);
434
                            $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}";
435
                            break;
436
                    }
437
438
                    if ($msg == "skip") {
439
                        return null;
440
                    }
441
                    $this->logger->addInfo("Notification sent to channel {$this->toDiscordChannel}, Message - {$msg}");
442
                    $guild = $discord->guilds->get('id', $this->guild);
443
                    $channel = $guild->channels->get('id', $channelID);
444
                    $channel->sendMessage($msg, false);
445
                    // Find the maxID so we don't output this message again in the future
446
                    $this->maxID = max($notificationID, $this->maxID);
447
                    $this->newestNotificationID = $this->maxID;
448
                    setPermCache("newestNotificationID", $this->maxID);
449
                }
450
            }
451
452
            $this->logger->addInfo("Next Notification Check At: {$cacheTimer} EVE Time");
453
        } catch (Exception $e) {
454
            $this->logger->addInfo("Notification Error: " . $e->getMessage());
455
        }
456
        return null;
457
    }
458
    /**
459
     * @param $keyID
460
     * @param $vCode
461
     * @param $characterID
462
     * @param $notificationID
463
     * @return string
464
     */
465
    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...
466
    {
467
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
468
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
469
            "SimpleXMLElement", LIBXML_NOCDATA)), true);
470
        $data = $data["result"]["rowset"]["row"];
471
        return $data;
472
    }
473
    /**
474
     *
475
     */
476
    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...
477
    {
478
    }
479
480
481
    /**
482
     * @return array
483
     */
484
    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...
485
    {
486
        return array(
487
            "name" => "",
488
            "trigger" => array(""),
489
            "information" => "");
490
    }
491
}
492