Passed
Push — master ( fb6ce1...7c7d88 )
by Bob
02:59
created

notifications::information()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 5
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
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
use Discord\Discord;
26
use Discord\Parts\Channel\Channel;
27
use Discord\Parts\Channel\Message;
28
29
/**
30
 * Class notifications.
31
 *
32
 * @property  keyID
33
 * @property  vCode
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
    public $config;
41
    /*
42
     * @var
43
     */
44
    public $discord;
45
    /*
46
     * @var
47
     */
48
    public $logger;
49
    /*
50
     * @var
51
     */
52
    public $nextCheck;
53
    /*
54
     * @var
55
     */
56
    public $keys;
57
    /*
58
     * @var
59
     */
60
    public $keyCount;
61
    /*
62
     * @var
63
     */
64
    public $toDiscordChannel;
65
    /*
66
     * @var
67
     */
68
    public $newestNotificationID;
69
    /*
70
     * @var
71
     */
72
    public $maxID;
73
    /*
74
     * @var
75
     */
76
    public $charApi;
77
    /*
78
     * @var
79
     */
80
    public $corpApi;
81
    /*
82
     * @var
83
     */
84
    public $alliApi;
85
86
    /**
87
     * @param $config
88
     * @param $discord
89
     * @param $logger
90
     */
91
    public function init($config, $discord, $logger)
92
    {
93
        $this->config = $config;
94
        $this->discord = $discord;
95
        $this->logger = $logger;
96
        $this->toDiscordChannel = $config['plugins']['notifications']['channelID'];
97
        $this->newestNotificationID = getPermCache('newestNotificationID');
98
        $this->maxID = 0;
99
        $this->keyID = $config['eve']['apiKeys']['user1']['keyID'];
0 ignored issues
show
Bug introduced by
The property keyID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
100
        $this->vCode = $config['eve']['apiKeys']['user1']['vCode'];
0 ignored issues
show
Bug introduced by
The property vCode does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
101
        $this->characterID = $config['eve']['apiKeys']['user1']['characterID'];
0 ignored issues
show
Bug introduced by
The property characterID does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
102
        // Rena APIs
103
        $this->charApi = 'http://rena.karbowiak.dk/api/character/information/';
104
        $this->corpApi = 'http://rena.karbowiak.dk/api/corporation/information/';
105
        $this->alliApi = 'http://rena.karbowiak.dk/api/alliance/information/';
106
        $lastCheck = getPermCache("notificationsLastChecked{$this->keyID}");
107
        if ($lastCheck == null) {
108
            // Schedule it for right now if first run
109
            setPermCache("notificationsLastChecked{$this->keyID}", time() - 5);
110
        }
111
    }
112
113
114 View Code Duplication
    public function tick()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

Loading history...
115
    {
116
        $lastChecked = getPermCache("notificationsLastChecked{$this->keyID}");
117
        $keyID = $this->keyID;
118
        $vCode = $this->vCode;
119
        $characterID = $this->characterID;
120
121
        if ($lastChecked <= time()) {
122
            $this->logger->addInfo("Checking API Key {$keyID} for notifications..");
123
            $this->getNotifications($keyID, $vCode, $characterID);
124
        }
125
    }
126
127
    /**
128
     * @param $keyID
129
     * @param $vCode
130
     * @param $characterID
131
     *
132
     * @return null
133
     */
134
    public function getNotifications($keyID, $vCode, $characterID)
135
    {
136
        try {
137
            $url = "https://api.eveonline.com/char/Notifications.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}";
138
            $xml = makeApiRequest($url);
139
            date_default_timezone_set('UTC');
140
            $cached = $xml->cachedUntil[0];
141
            $baseUnix = strtotime($cached);
142
            $cacheClr = $baseUnix - 13500;
143 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...
144
                $weirdTime = time() + 1830;
145
                $cacheTimer = gmdate('Y-m-d H:i:s', $weirdTime);
146
                setPermCache("notificationsLastChecked{$keyID}", $weirdTime);
147
            } else {
148
                $cacheTimer = gmdate('Y-m-d H:i:s', $cacheClr);
149
                setPermCache("notificationsLastChecked{$keyID}", $cacheClr);
150
            }
151
            $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
152
                'SimpleXMLElement', LIBXML_NOCDATA)), true);
153
            $data = $data['result']['rowset']['row'];
154
            // If there is no data, just quit..
155
            if (empty($data)) {
156
                return;
157
            }
158
            $fixedData = [];
159
            // Sometimes there is only ONE notification, so.. yeah..
160
            if (isset($data['@attributes'])) {
161
                $fixedData[] = $data['@attributes'];
162
            }
163
            if (count($data) > 1) {
164
                foreach ($data as $multiNotif) {
165
                    $fixedData[] = $multiNotif['@attributes'];
166
                }
167
            }
168
            foreach ($fixedData as $notification) {
169
                $notificationID = $notification['notificationID'];
170
                $typeID = $notification['typeID'];
171
                $sentDate = $notification['sentDate'];
172
                if ($notificationID > $this->newestNotificationID) {
173
                    $notificationString = explode("\n", $this->getNotificationText($keyID, $vCode, $characterID,
174
                        $notificationID));
175
                    switch ($typeID) {
176
                        case 5: // War Declared
177
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
178
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
179
                            $delayHours = trim(explode(': ', $notificationString[3])[1]);
180
                            $msg = "@everyone | War declared by {$aggAllianceName}. Fighting begins in roughly {$delayHours} hours.";
181
                            break;
182
                        case 7: // War Declared corp
183
                            $aggCorpID = trim(explode(': ', $notificationString[2])[1]);
184
                            $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName'];
185
                            $msg = "@everyone | War declared by {$aggCorpName}. Fighting begins in roughly 24 hours.";
186
                            break;
187
                        case 8: // Alliance war invalidated by CONCORD
188
                            $aggAllianceID = trim(explode(': ', $notificationString[2])[1]);
189
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
190
                            $msg = "War declared by {$aggAllianceName} has been invalidated. Fighting ends in roughly 24 hours.";
191
                            break;
192
                        case 10: // Bill issued
193
                            $msg = 'skip';
194
                            break;
195
                        case 14: // Bounty payment
196
                            $msg = 'skip';
197
                            break;
198
                        case 16: // Mail
199
                            $msg = 'skip';
200
                            break;
201
                        case 19: // corp tax changed
202
                            $corpID = trim(explode(': ', $notificationString[0])[1]);
203
                            $corpName = $this->apiData('corp', $corpID)['corporationName'];
204
                            $oldTax = trim(explode(': ', $notificationString[2])[1]);
205
                            $newTax = trim(explode(': ', $notificationString[1])[1]);
206
                            $msg = "{$corpName} tax changed from {$oldTax}% to {$newTax}%";
207
                            break;
208
                        case 21: // member left corp
209
                            $msg = 'skip';
210
                            break;
211
                        case 35: // Insurance payment
212
                            $msg = 'skip';
213
                            break;
214 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...
215
                            $systemID = trim(explode(': ', $notificationString[2])[1]);
216
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
217
                                'solarSystemName', [':id' => $systemID], 'ccp');
218
                            $allianceID = trim(explode(': ', $notificationString[0])[1]);
219
                            $allianceName = $this->apiData('alli', $allianceID)['allianceName'];
220
                            $msg = "{$allianceName} has lost control of **{$systemName}**";
221
                            break;
222 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...
223
                            $systemID = trim(explode(': ', $notificationString[2])[1]);
224
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
225
                                'solarSystemName', [':id' => $systemID], 'ccp');
226
                            $allianceID = trim(explode(': ', $notificationString[0])[1]);
227
                            $allianceName = $this->apiData('alli', $allianceID)['allianceName'];
228
                            $msg = "{$allianceName} now controls **{$systemName}**";
229
                            break;
230
                        case 52: // clone revoked
231
                            $msg = 'skip';
232
                            break;
233
                        case 57: // jump clone destruction
234
                            $msg = 'skip';
235
                            break;
236
                        case 71: // Mission Expiration
237
                            $msg = 'skip';
238
                            break;
239
                        case 75: // POS / POS Module under attack
240
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
241
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
242
                            $aggCorpID = trim(explode(': ', $notificationString[1])[1]);
243
                            $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName'];
244
                            $aggID = trim(explode(': ', $notificationString[2])[1]);
245
                            $aggCharacterName = $this->apiData('char', $aggID)['characterName'];
246
                            $armorValue = trim(explode(': ', $notificationString[3])[1]);
247
                            $hullValue = trim(explode(': ', $notificationString[4])[1]);
248
                            $moonID = trim(explode(': ', $notificationString[5])[1]);
249
                            $moonName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id',
250
                                'itemName', [':id' => $moonID], 'ccp');
251
                            $shieldValue = trim(explode(': ', $notificationString[6])[1]);
252
                            $solarSystemID = trim(explode(': ', $notificationString[7])[1]);
253
                            $typeID = trim(explode(': ', $notificationString[8])[1]);
254
                            $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id',
255
                                'typeName', [':id' => $typeID], 'ccp');
256
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
257
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
258
                            $msg = "{$typeName} under attack in **{$systemName} - {$moonName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
259
                            break;
260
                        case 76: // Tower resource alert
261
                            $moonID = trim(explode(': ', $notificationString[2])[1]);
262
                            $moonName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id',
263
                                'itemName', [':id' => $moonID], 'ccp');
264
                            $solarSystemID = trim(explode(': ', $notificationString[3])[1]);
265
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
266
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
267
                            $blocksRemaining = trim(explode(': ', $notificationString[6])[1]);
268
                            $typeID = trim(explode(': ', $notificationString[7])[1]);
269
                            $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id',
270
                                'typeName', [':id' => $typeID], 'ccp');
271
                            $msg = "POS in {$systemName} - {$moonName} needs fuel. Only {$blocksRemaining} {$typeName}'s remaining.";
272
                            break;
273
                        case 88: // IHUB is being attacked
274
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
275
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
276
                            $aggCorpID = trim(explode(': ', $notificationString[0])[1]);
277
                            $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName'];
278
                            $aggID = trim(explode(': ', $notificationString[1])[1]);
279
                            $aggCharacterName = $this->apiData('char', $aggID)['characterName'];
280
                            $armorValue = trim(explode(': ', $notificationString[3])[1]);
281
                            $hullValue = trim(explode(': ', $notificationString[4])[1]);
282
                            $shieldValue = trim(explode(': ', $notificationString[5])[1]);
283
                            $solarSystemID = trim(explode(': ', $notificationString[6])[1]);
284
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
285
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
286
                            $msg = "IHUB under attack in **{$systemName}** by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Status: Hull: {$hullValue}, Armor: {$armorValue}, Shield: {$shieldValue}";
287
                            break;
288
                        case 93: // Customs office is being attacked
289
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
290
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
291
                            $aggCorpID = trim(explode(': ', $notificationString[0])[1]);
292
                            $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName'];
293
                            $aggID = trim(explode(': ', $notificationString[2])[1]);
294
                            $aggCharacterName = $this->apiData('char', $aggID)['characterName'];
295
                            $planetID = trim(explode(': ', $notificationString[3])[1]);
296
                            $planetName = dbQueryField('SELECT itemName FROM mapAllCelestials WHERE itemID = :id',
297
                                'itemName', [':id' => $planetID], 'ccp');
298
                            $shieldValue = trim(explode(': ', $notificationString[5])[1]);
299
                            $solarSystemID = trim(explode(': ', $notificationString[6])[1]);
300
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
301
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
302
                            $msg = "Customs Office under attack in **{$systemName}** ($planetName) by {$aggCharacterName} ({$aggCorpName} / {$aggAllianceName}). Shield Status: {$shieldValue}";
303
                            break;
304
                        case 94: // POCO Reinforced
305
                            $msg = 'Customs Office reinforced.';
306
                            break;
307
                        case 95: // IHub Transfer
308
                            $msg = 'skip';
309
                            break;
310
                        case 103: // War support offer? I think?
311
                            $msg = 'skip';
312
                            break;
313
                        case 111: // Bounty
314
                            $msg = 'skip';
315
                            break;
316
                        case 128: // Corp App
317
                            $msg = 'skip';
318
                            break;
319
                        case 130: // Corp app withdrawn?
320
                            $msg = 'skip';
321
                            break;
322
                        case 138: // Clone activation
323
                            $msg = 'skip';
324
                            break;
325
                        case 140: // Kill report
326
                            $msg = 'skip';
327
                            break;
328
                        case 141: // Kill report
329
                            $msg = 'skip';
330
                            break;
331 View Code Duplication
                        case 147: // Entosis has stated
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...
332
                            $systemID = trim(explode(': ', $notificationString[0])[1]);
333
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
334
                                'solarSystemName', [':id' => $systemID], 'ccp');
335
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
336
                            $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id',
337
                                'typeName', [':id' => $typeID], 'ccp');
338
                            $msg = "@everyone | Entosis has started in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
339
                            break;
340 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...
341
                            $systemID = trim(explode(': ', $notificationString[0])[1]);
342
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
343
                                'solarSystemName', [':id' => $systemID], 'ccp');
344
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
345
                            $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id',
346
                                'typeName', [':id' => $typeID], 'ccp');
347
                            $msg = "Entosis has enabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
348
                            break;
349 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...
350
                            $systemID = trim(explode(': ', $notificationString[0])[1]);
351
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
352
                                'solarSystemName', [':id' => $systemID], 'ccp');
353
                            $typeID = trim(explode(': ', $notificationString[1])[1]);
354
                            $typeName = dbQueryField('SELECT typeName FROM invTypes WHERE typeID = :id',
355
                                'typeName', [':id' => $typeID], 'ccp');
356
                            $msg = "Entosis has disabled a module in **{$systemName}** on **{$typeName}** (Date: **{$sentDate}**)";
357
                            break;
358 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...
359
                            $systemID = trim(explode(': ', $notificationString[2])[1]);
360
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id', 'solarSystemName', [':id' => $systemID], 'ccp');
361
                            $msg = "Hostile entosis successful. A structure in **{$systemName}** has entered reinforced mode.";
362
                            break;
363 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...
364
                            $systemID = trim(explode(': ', $notificationString[2])[1]);
365
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
366
                                'solarSystemName', [':id' => $systemID], 'ccp');
367
                            $msg = "Command nodes decloaking for **{$systemName}**";
368
                            break;
369 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...
370
                            $systemID = trim(explode(': ', $notificationString[1])[1]);
371
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
372
                                'solarSystemName', [':id' => $systemID], 'ccp');
373
                            $msg = "Station in **{$systemName}** has now entered freeport mode.";
374
                            break;
375
                        case 182: //  Citadel being anchored
376
                            $corpName = trim(explode(': ', $notificationString[1])[1]);
377
                            $solarSystemID = trim(explode(': ', $notificationString[2])[1]);
378
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
379
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
380
                            $msg = "Citadel owned by **{$corpName}** is being anchored in **{$systemName}**.";
381
                            break;
382
                        case 184: //  Citadel under attack
383
                            $aggID = trim(explode(': ', $notificationString[7])[1]);
384
                            $aggCharacterName = $this->apiData('char', $aggID)['characterName'];
385
                            $solarSystemID = trim(explode(': ', $notificationString[15])[1]);
386
                            $aggAllianceID = trim(explode(': ', $notificationString[0])[1]);
387
                            $aggAllianceName = $this->apiData('alli', $aggAllianceID)['allianceName'];
388
                            $aggCorpID = trim(explode('- ', $notificationString[11])[1]);
389
                            $aggCorpName = $this->apiData('corp', $aggCorpID)['corporationName'];
390
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
391
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
392
                            $msg = "@everyone | Citadel under attack in **{$systemName}** by **{$aggCharacterName}** ({$aggCorpName} / {$aggAllianceName}).";
393
                            break;
394 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...
395
                            $solarSystemID = trim(explode(': ', $notificationString[0])[1]);
396
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
397
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
398
                            $msg = "Citadel now online in **{$systemName}**.";
399
                            break;
400 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...
401
                            $corpID = trim(explode('- ', $notificationString[3])[1]);
402
                            $corpName = $this->apiData('corp', $corpID)['corporationName'];
403
                            $solarSystemID = trim(explode(': ', $notificationString[5])[1]);
404
                            $systemName = dbQueryField('SELECT solarSystemName FROM mapSolarSystems WHERE solarSystemID = :id',
405
                                'solarSystemName', [':id' => $solarSystemID], 'ccp');
406
                            $msg = "Citadel owned by **{$corpName}** in **{$systemName}** has been destroyed.";
407
                            break;
408
                        case 199: // citadel delivery
409
                            $msg = 'skip';
410
                            break;
411
                        default: // Unknown typeID
412
                            $string = implode(' ', $notificationString);
413
                            $msg = "typeID {$typeID} is an unmapped notification, send Mr Twinkie this whole message via evemail or github issue. {$string}";
414
                            break;
415
                    }
416
417
                    if ($msg == 'skip') {
418
                        return;
419
                    }
420
                    if ($msg == '') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
421
                    }
422
                    $this->logger->addInfo("Notification sent to channel {$this->toDiscordChannel}, Message - {$msg}");
423
                    $channelID = $this->toDiscordChannel;
424
                    $channel = Channel::find($channelID);
425
                    $channel->sendMessage($msg, false);
426
                    // Find the maxID so we don't output this message again in the future
427
                    $this->maxID = max($notificationID, $this->maxID);
428
                    $this->newestNotificationID = $this->maxID;
429
                    setPermCache('newestNotificationID', $this->maxID);
430
                }
431
            }
432
433
            $this->logger->addInfo("Next Notification Check At: {$cacheTimer} EVE Time");
434
        } catch (Exception $e) {
435
            $this->logger->addInfo('Notification Error: '.$e->getMessage());
436
        }
437
    }
438
439
    /**
440
     * @param $keyID
441
     * @param $vCode
442
     * @param $characterID
443
     * @param $notificationID
444
     *
445
     * @return string
446
     */
447
    public function getNotificationText($keyID, $vCode, $characterID, $notificationID)
448
    {
449
        $url = "https://api.eveonline.com/char/NotificationTexts.xml.aspx?keyID={$keyID}&vCode={$vCode}&characterID={$characterID}&IDs={$notificationID}";
450
        $data = json_decode(json_encode(simplexml_load_string(downloadData($url),
451
            'SimpleXMLElement', LIBXML_NOCDATA)), true);
452
        $data = $data['result']['rowset']['row'];
453
454
        return $data;
455
    }
456
457
458
    public function onMessage()
459
    {
460
    }
461
462
    /**
463
     * @param string $type
464
     * @param string $typeID
465
     *
466
     * @return mixed
467
     */
468
    public function apiData($type, $typeID)
469
    {
470
        $downloadFrom = '';
471
        switch ($type) {
472
            case 'char':
473
                $downloadFrom = $this->charApi;
474
                break;
475
            case 'corp':
476
                $downloadFrom = $this->corpApi;
477
                break;
478
            case 'alli':
479
                $downloadFrom = $this->alliApi;
480
                break;
481
        }
482
483
        return json_decode(downloadData($downloadFrom.$typeID.'/'), true);
484
    }
485
486
    /**
487
     * @return array
488
     */
489
    public function information()
490
    {
491
        return [
492
            'name'        => '',
493
            'trigger'     => [''],
494
            'information' => '', ];
495
    }
496
}
497