Passed
Pull Request — master (#196)
by
unknown
03:02
created

authCheck   D

Complexity

Total Complexity 123

Size/Duplication

Total Lines 525
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 100
loc 525
rs 4.8717
c 0
b 0
f 0
wmc 123
lcom 1
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 38 5
C tick() 0 35 8
D checkPermissions() 44 167 56
C checkAuthState() 8 79 14
F nameReset() 48 140 29
C standingsUpdate() 0 23 11

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

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

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

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

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

1
<?php
2
/**
3
 * The MIT License (MIT)
4
 *
5
 * Copyright (c) 2016 Robert Sardinia
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
 * SOFTWARE.
24
 */
25
26
27
/**
28
 * Class fileAuthCheck
29
 * @property int nextCheck
30
 */
31
class authCheck
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...
32
{
33
34
    /**
35
     * @var
36
     */
37
    private $config;
38
    private $db;
39
    private $dbUser;
40
    private $dbPass;
41
    private $dbName;
42
    private $guildID;
43
    private $corpTickers;
44
    private $authGroups;
45
    private $exempt;
46
    private $alertChannel;
47
    private $guild;
48
    private $nameEnforce;
49
    private $standingsBased;
50
    private $nameCheck;
51
    private $apiKey;
52
    private $discord;
53
    private $logger;
54
55
    /**
56
     * @param $config
57
     * @param $discord
58
     * @param $logger
59
     */
60
    public function init($config, $discord, $logger)
61
    {
62
        $this->config = $config;
63
        $this->discord = $discord;
64
        $this->logger = $logger;
65
        $this->db = $config['database']['host'];
66
        $this->dbUser = $config['database']['user'];
67
        $this->dbPass = $config['database']['pass'];
68
        $this->dbName = $config['database']['database'];
69
        $this->guildID = $config['bot']['guild'];
70
        $this->exempt = $config['plugins']['auth']['exempt'];
71
        $this->corpTickers = $config['plugins']['auth']['corpTickers'];
72
        $this->nameEnforce = $config['plugins']['auth']['nameEnforce'];
73
        $this->standingsBased = $config['plugins']['auth']['standings']['enabled'];
74
        $this->apiKey = $config['eve']['apiKeys'];
75
        $this->authGroups = $config['plugins']['auth']['authGroups'];
76
        $this->alertChannel = $config['plugins']['auth']['alertChannel'];
77
        $this->guild = $config['bot']['guild'];
78
        $this->nextCheck = 0;
79
80
        //Set name check to happen if corpTicker or nameEnforce is set
81
        if ($this->nameEnforce === 'true' || $this->corpTickers === 'true') {
82
            $this->nameCheck = 'true';
83
        }
84
85
        //check if cache has been set
86
        $permsChecked = getPermCache('permsLastChecked');
87
        $namesChecked = getPermCache('nextRename');
88
        if ($namesChecked === NULL) {
89
            setPermCache('nextRename', time());
90
        }
91
92
        //if not set set for now (30 minutes from now for role removal)
93
        if ($permsChecked === NULL) {
94
            setPermCache('permsLastChecked', time() - 1);
95
            setPermCache('authStateLastChecked', time() + 1);
96
        }
97
    }
98
99
    public function tick()
100
    {
101
        // What was the servers last reported state
102
        $lastStatus = getPermCache('serverState');
103
        if ($lastStatus === 'online') {
104
            $permsChecked = getPermCache('permsLastChecked');
105
            $stateChecked = getPermCache('authStateLastChecked');
106
            $namesChecked = getPermCache('nextRename');
107
            $standingsChecked = getPermCache('nextStandingsCheck');
108
109
            if ($permsChecked <= time()) {
110
                $this->logger->addInfo('AuthCheck: Checking for users who have left corp/alliance....');
111
                $this->checkPermissions();
112
                $this->logger->addInfo('AuthCheck: Corp/alliance check complete.');
113
            }
114
115
            if ($stateChecked <= time()) {
116
                $this->logger->addInfo('AuthCheck: Checking for users who have been wrongly given roles....');
117
                $this->checkAuthState();
118
                $this->logger->addInfo('AuthCheck: Role check complete.');
119
            }
120
121
            if ($this->nameCheck === 'true' && $namesChecked <= time()) {
122
                $this->logger->addInfo('AuthCheck: Resetting player names....');
123
                $this->nameReset();
124
                $this->logger->addInfo('AuthCheck: Names reset.');
125
            }
126
127
            if ($this->standingsBased === 'true' && $standingsChecked <= time()) {
128
                $this->logger->addInfo('AuthCheck: Updating Standings');
129
                $this->standingsUpdate();
130
                $this->logger->addInfo('AuthCheck: Standings Updated');
131
            }
132
        }
133
    }
134
135
    /**
136
     * @return null
137
     */
138
139
    //Remove members who have roles but never authed
140
    private function checkPermissions()
141
    {
142
        //Get guild object
143
        $guild = $this->discord->guilds->get('id', $this->guildID);
144
145
        //Establish connection to mysql
146
        $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName);
147
148
        //$sql = "SELECT characterID, discordID, eveName, role FROM authUsers WHERE active='yes'";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
149
		$sql = "SELECT characterID, discordID, eveName, active, role FROM authUsers";
150
151
        $result = $conn->query($sql);
152
153
        //Set empty arrays
154
        $corpArray = array();
155
        $allianceArray = array();
156
157
        // If config is outdated
158 View Code Duplication
        if (null === $this->authGroups) {
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
            $msg = '**Auth Failure:** Please update the bots config to the latest version.';
160
            queueMessage($msg, $this->alertChannel, $this->guild);
161
            $nextCheck = time() + 10800;
162
            setPermCache('permsLastChecked', $nextCheck);
163
            return null;
164
        }
165
166
        //Set corp/ally id arrays
167
        foreach ($this->authGroups as $authGroup) {
168
            if ($authGroup['corpID'] !== 0) {
169
                $corpArray[] = (int) $authGroup['corpID'];
170
            }
171
            if ($authGroup['allianceID'] !== 0) {
172
                $allianceArray[] = (int) $authGroup['allianceID'];
173
            }
174
        }
175
176
        if ($result->num_rows >= 1) {
177
            while ($rows = $result->fetch_assoc()) {
178
				$charID = $rows['characterID'];
179
				$discordID = $rows['discordID'];
180
				$role = $rows['role'];
181
				$member = $guild->members->get('id', $discordID);
182
				$eveName = $rows['eveName'];
183
				//Check if member has roles
184
				if (null === @$member->roles) {
185
					continue;
186
				}
187
188
				//Auth things
189
				$character = characterDetails($charID);
190
				//if issue with esi, skip
191
				$timeout = 0;
192 View Code Duplication
				while (null === $character) { //try 10 times to pull characterDetails
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...
193
					if ($timeout > 9) {
194
						continue;
195
					}
196
					else{
197
						$character = characterDetails($charID);
198
						$timeout++;
199
					}
200
				}
201
				$corporationID = $character['corporation_id'];
202
				$corporationDetails = corpDetails($corporationID);
203
				$timeout = 0;
204
				while (null === $corporationDetails) { //try 10 times to pull corporationDetails
205
					if ($timeout > 9) {
206
						continue;
207
					}
208
					else{
209
						$corporationDetails = corpDetails($corporationID);
210
						$timeout++;
211
					}
212
				}
213
				$allianceID = @$corporationDetails['alliance_id'];
214
				if ($rows['active'] == "yes"){
215
216
					//check if user authed based on standings
217
					$standings = null;
218
					if ($role === 'blue' || 'neut' || 'red') {
219
						$allianceContacts = getContacts($allianceID);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $allianceContacts is correct as getContacts($allianceID) (which targets getContacts()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
220
						$corpContacts = getContacts($corporationID);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $corpContacts is correct as getContacts($corporationID) (which targets getContacts()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
221
						if ($role === 'blue' && ((int) $allianceContacts['standing'] === 5 || 10 || (int) $corpContacts['standing'] === 5 || 10)) {
222
							$standings = 1;
223
						}
224
						if ($role === 'red' && ((int) $allianceContacts['standing'] === -5 || -10 || (int) $corpContacts['standing'] === -5 || -10)) {
225
							$standings = 1;
226
						}
227
						if ($role === 'neut' && ((int) $allianceContacts['standing'] === 0 || (int) $corpContacts['standing'] === 0 || (@(int) $allianceContacts['standings'] === null || '' && @(int) $corpContacts['standings'] === null || ''))) {
228
							$standings = 1;
229
						}
230
					}
231
					if (!in_array((int) $allianceID, $allianceArray) && !in_array((int) $corporationID, $corpArray) && null === $standings) {
232
						// Deactivate user in database
233
						$sql = "UPDATE authUsers SET active='no' WHERE discordID='$discordID'";
234
						$this->logger->addInfo("AuthCheck: {$eveName} account has been deactivated as they are no longer in a correct corp/alliance.");
235
						$conn->query($sql);
236
						continue;
237
					}
238
				}
239
				elseif($rows['active'] == "no") {
240
					$roles = @$guild->roles;
241
					$member = @$guild->members->get('id', $discordID);
242
					if (in_array((int) $allianceID, $allianceArray) || in_array((int) $corporationID, $corpArray)) {
243
						foreach ($this->authGroups as $authGroup) {
244
							//Check if it's set to match corp and alliance
245
							if ($authGroup['corpID'] !== 0 && $authGroup['allianceID'] !== 0) {
246
								//Check if corpID matches
247
								if ($corpID === $authGroup['corpID'] && $allianceID === $authGroup['allianceID']) {
0 ignored issues
show
Bug introduced by
The variable $corpID does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
248
									foreach ($roles as $role) {
249
										if ((string) $role->name === (string) $authGroup['corpMemberRole']) {
250
											$member->addRole($role);
251
										}
252
										if ((string) $role->name === (string) $authGroup['allyMemberRole']) {
253
											$member->addRole($role);
254
											$role = 'corp/ally';
255
											$guild->members->save($member);
256
											// Deactivate user in database
257
											$sql = "UPDATE authUsers SET active='yes' WHERE discordID='$discordID'";
258
											$this->logger->addInfo("AuthCheck: {$eveName} account has been activates as they are in correct corp/alliance.");
259
											$conn->query($sql);
260
										}
261
									}
262
									break;
263
								}
264
							} elseif ($authGroup['corpID'] !== 0 || $authGroup['allianceID'] !== 0) {
265
								//Check if corpID matches
266 View Code Duplication
								if ($corpID === $authGroup['corpID']) {
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...
267
									foreach ($roles as $role) {
268
										if ((string) $role->name === (string) $authGroup['corpMemberRole']) {
269
											$member->addRole($role);
270
											$role = 'corp';
271
											$guild->members->save($member);
272
											// Deactivate user in database
273
											$sql = "UPDATE authUsers SET active='yes' WHERE discordID='$discordID'";
274
											$this->logger->addInfo("AuthCheck: {$eveName} account has been deactivated as they are in correct corp/alliance.");
275
											$conn->query($sql);
276
										}
277
									}
278
									break;
279
								}
280
								//Check if allianceID matches
281 View Code Duplication
								if ($allianceID === $authGroup['allianceID'] && $authGroup['allianceID'] !== 0) {
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...
282
									foreach ($roles as $role) {
283
										if ((string) $role->name === (string) $authGroup['allyMemberRole']) {
284
											$member->addRole($role);
285
											$role = 'ally';
286
											$guild->members->save($member);
287
											// Deactivate user in database
288
											$sql = "UPDATE authUsers SET active='yes' WHERE discordID='$discordID'";
289
											$this->logger->addInfo("AuthCheck: {$eveName} account has been deactivated as they are in correct corp/alliance.");
290
											$conn->query($sql);
291
										}
292
									}
293
									break;
294
								}
295
							}
296
						}
297
					}
298
				}
299
				$nextCheck = time() + 10800;
300
				setPermCache('permsLastChecked', $nextCheck);
301
			}
302
        }
303
        $nextCheck = time() + 10800;
304
        setPermCache('permsLastChecked', $nextCheck);
305
        return null;
306
    }
307
308
    //Check user corp/alliance affiliation
309
310
311
    private function checkAuthState()
312
    {
313
314
        //Check if exempt roles are set
315
        if (null === $this->exempt) {
316
            $this->exempt = '0';
317
        }
318
319
        // If config is outdated
320 View Code Duplication
        if (null === $this->authGroups) {
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...
321
            $msg = '**Auth Failure:** Please update the bots config to the latest version.';
322
            queueMessage($msg, $this->alertChannel, $this->guild);
323
            //queue up next check
324
            $nextCheck = time() + 1800;
325
            setPermCache('authStateLastChecked', $nextCheck);
326
            return null;
327
        }
328
329
        //Establish connection to mysql
330
        $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName);
331
332
        //get bot ID so we don't remove out own roles
333
        $botID = $this->discord->id;
334
335
        //Get guild object
336
        $guild = $this->discord->guilds->get('id', $this->guildID);
337
338
        //Check to make sure guildID is set correctly
339
        if (null === $guild) {
340
            $this->logger->addError('Config Error: Ensure the guild entry in the config is the guildID (aka serverID) for the main server that the bot is in.');
341
            $nextCheck = time() + 7200;
342
            setPermCache('authLastChecked', $nextCheck);
343
            return null;
344
        }
345
346
        //create empty array to store names
347
        $removedRoles = array();
348
        $userCount = 0;
349
350
        //Perform check if roles were added without permission
351
        foreach ($guild->members as $member) {
352
            $id = $member->id;
353
            $username = $member->username;
354
            $roles = $member->roles;
355
356
            //Skip to next member if this user has no roles
357
            if (null === $roles) {
358
                continue;
359
            }
360
            $sql = "SELECT * FROM authUsers WHERE discordID='$id' AND active='yes'";
361
            $result = $conn->query($sql);
362
363
            //If they are NOT active in the db, check for roles to remove
364
            if ($result->num_rows === 0) {
365
                $userCount++;
366
                foreach ($roles as $role) {
367
                    if ($id !== $botID && !in_array($role->name, $this->exempt, true)) {
368
                        $member->removeRole($role);
369
                        $guild->members->save($member);
370
                        // Add users name to array
371
                        if (!in_array($username, $removedRoles)) {
372
                            $removedRoles[] = $username;
373
                        }
374
                    }
375
                }
376
            }
377
        }
378
        //Report removed users to log and channel
379
        $nameList = implode(', ', $removedRoles);
380
        if ($userCount > 0 && strlen($nameList) > 3 && null !== $nameList) {
381
            $msg = "Following users roles have been removed - {$nameList}";
382
            queueMessage($msg, $this->alertChannel, $this->guild);
383
            $this->logger->addInfo("AuthCheck: Roles removed from {$nameList}");
384
        }
385
        //queue up next check
386
        $nextCheck = time() + 1800;
387
        setPermCache('authStateLastChecked', $nextCheck);
388
        return null;
389
    }
390
391
    private function nameReset()
392
    {
393
        //Get guild object
394
        $guild = $this->discord->guilds->get('id', $this->guildID);
395
396
        //Get name queue status
397
        $x = (int) getPermCache('nameQueueState');
398
399
        //Establish connection to mysql
400
        $conn = new mysqli($this->db, $this->dbUser, $this->dbPass, $this->dbName);
401
        $sql = "SELECT id FROM authUsers WHERE active='yes'";
402
        $count = $conn->query($sql);
403
        $rowAmount = round($count->num_rows / 2);
404
        if ($x === 1) {
405
            $sql = "SELECT characterID, discordID, eveName  FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount} OFFSET {$rowAmount}";
406
            setPermCache('nameQueueState', 0);
407
        } else {
408
            $sql = "SELECT characterID, discordID, eveName  FROM authUsers WHERE active='yes' ORDER BY id ASC LIMIT {$rowAmount}";
409
            setPermCache('nameQueueState', 1);
410
        }
411
        $result = $conn->query($sql);
412
413
        // If config is outdated
414 View Code Duplication
        if (null === $this->authGroups) {
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...
415
            $msg = '**Auth Failure:** Please update the bots config to the latest version.';
416
            queueMessage($msg, $this->alertChannel, $this->guild);
417
            $nextCheck = time() + 1800;
418
            setPermCache('nextRename', $nextCheck);
419
            return null;
420
        }
421
422
        if (@$result->num_rows >= 1) {
423
            while ($rows = $result->fetch_assoc()) {
424
                $charID = $rows['characterID'];
425
                $discordID = $rows['discordID'];
426
                $member = $guild->members->get('id', $discordID);
427
                $eveName = $rows['eveName'];
428
                //Check if member has roles
429
                if (null === @$member->roles) {
430
                    continue;
431
                }
432
433
                //Get current nickname
434
                $guild = $this->discord->guilds->get('id', $this->guildID);
435
                $member = $guild->members->get('id', $discordID);
436
                $nickName = $member->nick;
437
                $userName = $member->user->username;
438
                //If nick isn't set than make it username
439
                if ($nickName === '' || null === $nickName) {
440
                    $nickName = $userName;
441
                }
442
443
                //Check for bad tickers
444
                if (strpos($nickName, '[U]') !== false) {
445
                    $nickName = str_replace('[U]', '', $nickName);
446
                    queueRename($discordID, $nickName, $this->guildID);
447
                    continue;
448
                }
449
450
                //corp ticker
451
                if ($this->corpTickers === 'true') {
452
					$timeout = 0;
453
					$character = characterDetails($charID);
454 View Code Duplication
					while (null === $character) { //try 10 times to pull characterDetails
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...
455
						if ($timeout > 9) {
456
							continue;
457
						}
458
						else{
459
							$character = characterDetails($charID);
460
							$timeout++;
461
						}
462
					}
463
                    if (!array_key_exists('corporation_id', $character)) {
464
                        continue;
465
                    }
466
                    $corpInfo = getCorpInfo($character['corporation_id']);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $corpInfo is correct as getCorpInfo($character['corporation_id']) (which targets getCorpInfo()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
467
                    //Clean bad entries
468
                    if (@$corpInfo['corpTicker'] === 'U') {
469
                        deleteCorpInfo(@$corpInfo['corpID']);
470
                    }
471
                    $nick = null;
472 View Code Duplication
                    if (null !== @$corpInfo['corpTicker']) {
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...
473
                        $corpTicker = (string) $corpInfo['corpTicker'];
474
                        if ($this->nameEnforce === 'true') {
475
                            $nick = "[{$corpTicker}] {$eveName}";
476
                        } elseif ((string) $nickName === "[{$corpTicker}]") {
477
                            $nick = "[{$corpTicker}] {$userName}";
478
                        } elseif (strpos($nickName, $corpTicker) === false) {
479
                            $nick = "[{$corpTicker}] {$nickName}";
480
                        } elseif (strpos($nickName, $corpTicker) !== false) {
481
                            continue;
482
                        }
483
                        if ($nick !== $nickName) {
484
                            queueRename($discordID, $nick, $this->guildID);
485
                        }
486
                        continue;
487
                    }
488
                    $corporationDetails = corpDetails($character['corporation_id']);
489
                    if (null === $corporationDetails) {
490
                        continue;
491
                    }
492
                    $corpTicker = $corporationDetails['ticker'];
493
                    //Check for bad tickers (ESI ERROR?)
494
                    if (@$corpTicker === 'U') {
495
                        continue;
496
                    }
497
                    $corpName = (string) $corporationDetails['corporation_name'];
498 View Code Duplication
                    if (null !== $corpTicker) {
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...
499
                        if ($this->nameEnforce === 'true') {
500
                            $nick = "[{$corpTicker}] {$eveName}";
501
                        } elseif ((string) $nickName === "[{$corpTicker}]") {
502
                            $nick = "[{$corpTicker}] {$userName}";
503
                        } elseif (strpos($nickName, $corpTicker) === false) {
504
                            $nick = "[{$corpTicker}] {$nickName}";
505
                        } elseif (strpos($nickName, $corpTicker) !== false) {
506
                            continue;
507
                        }
508
                        if ($nick !== $nickName) {
509
                            queueRename($discordID, $nick, $this->guildID);
510
                            addCorpInfo($character['corporation_id'], $corpTicker, $corpName);
511
                        }
512
                        continue;
513
                    }
514
                    continue;
515
                }
516
                $nick = "{$eveName}";
517
                if ($nick !== $nickName) {
518
                    queueRename($discordID, $nick, $this->guildID);
519
                }
520
                continue;
521
            }
522
            $nextCheck = time() + 1800;
523
            setPermCache('nextRename', $nextCheck);
524
            return null;
525
        }
526
        $nextCheck = time() + 1800;
527
        setPermCache('nextRename', $nextCheck);
528
        return null;
529
530
    }
531
532
    private function standingsUpdate()
533
    {
534
        foreach ($this->apiKey as $apiKey) {
535
            if ((string) $apiKey['keyID'] === (string) $this->config['plugins']['auth']['standings']['apiKey']) {
536
                $url = "https://api.eveonline.com/char/ContactList.xml.aspx?keyID={$apiKey['keyID']}&vCode={$apiKey['vCode']}&characterID={$apiKey['characterID']}";
537
                $xml = makeApiRequest($url);
538
                if (empty($xml)) {
539
                    return null;
540
                }
541
                foreach ($xml->result->rowset as $contactType) {
542
                    if ((string) $contactType->attributes()->name === 'corporateContactList' || 'allianceContactList') {
543
                        foreach ($contactType->row as $contact) {
544
                            if (null !== $contact['contactID'] && $contact['contactName'] && $contact['standing']) {
545
                                addContactInfo($contact['contactID'], $contact['contactName'], $contact['standing']);
546
                            }
547
                        }
548
                    }
549
                }
550
            }
551
        }
552
        $nextCheck = time() + 86400;
553
        setPermCache('nextStandingsCheck', $nextCheck);
554
    }
555
}
556