We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 18 |
Paths | 1408 |
Total Lines | 80 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
2 | function logException(Throwable $e) { |
||
3 | global $account, $var, $player; |
||
4 | $errorType = 'Unexpected Game Error!'; |
||
5 | $message = ''; |
||
6 | $delim = "\n\n-----------\n\n"; |
||
7 | |||
8 | if (is_object($account)) { |
||
9 | $message .= 'Login: ' . $account->getLogin() . "\n" . |
||
10 | 'Account ID: ' . $account->getAccountID() . "\n" . |
||
11 | 'E-Mail: ' . $account->getEmail() . $delim; |
||
12 | } |
||
13 | $message .= 'Error Message: ' . $e . $delim; |
||
14 | |||
15 | $message .= '$var: ' . var_export($var, true); |
||
16 | |||
17 | // Don't display passwords input by users in the log message! |
||
18 | if (isset($_REQUEST['password'])) { |
||
19 | $_REQUEST['password'] = '*****'; |
||
20 | } |
||
21 | $message .= "\n\n" . '$_REQUEST: ' . var_export($_REQUEST, true); |
||
22 | $message .= $delim; |
||
23 | |||
24 | $message .= |
||
25 | 'User IP: ' . getIpAddress() . "\n" . |
||
26 | 'USING_AJAX: ' . (defined('USING_AJAX') ? var_export(USING_AJAX, true) : 'undefined') . "\n" . |
||
27 | 'URL: ' . (defined('URL') ? URL : 'undefined'); |
||
28 | |||
29 | try { |
||
30 | if (function_exists('release_lock')) { |
||
31 | release_lock(); //Try to release lock so they can carry on normally |
||
32 | } |
||
33 | } catch (Throwable $ee) { |
||
34 | $message .= $delim . |
||
35 | 'Releasing Lock Failed' . "\n" . |
||
36 | 'Message: ' . $ee . "\n"; |
||
37 | } |
||
38 | |||
39 | if (defined('SCRIPT_ID')) { |
||
40 | $message = 'Script: ' . SCRIPT_ID . $delim . $message . "\n\n"; |
||
41 | } |
||
42 | |||
43 | // Unconditionally send error message to the log |
||
44 | error_log($message); |
||
45 | |||
46 | if (defined('NPC_SCRIPT') && ENABLE_DEBUG) { |
||
47 | // In debug mode, we normally exit, but NPCs must cleanup after an error |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | if (ENABLE_DEBUG) { |
||
52 | // Display error message on the page and then exit |
||
53 | echo nl2br($message); |
||
54 | exit; |
||
|
|||
55 | } |
||
56 | |||
57 | // Send error message to the in-game auto bugs mailbox |
||
58 | if (is_object($player) && method_exists($player, 'sendMessageToBox')) { |
||
59 | $player->sendMessageToBox(BOX_BUGS_AUTO, $message); |
||
60 | } elseif (is_object($account) && method_exists($account, 'sendMessageToBox')) { |
||
61 | // Will be logged without a game_id |
||
62 | $account->sendMessageToBox(BOX_BUGS_AUTO, $message); |
||
63 | } else { |
||
64 | // Will be logged without a game_id or sender_id |
||
65 | SmrAccount::doMessageSendingToBox(0, BOX_BUGS_AUTO, $message, 0); |
||
66 | } |
||
67 | |||
68 | // Send error message to e-mail so that we have a permanent record |
||
69 | if (!empty(BUG_REPORT_TO_ADDRESSES)) { |
||
70 | $mail = setupMailer(); |
||
71 | $mail->Subject = (defined('PAGE_PREFIX') ? PAGE_PREFIX : '??? ') . |
||
72 | 'Automatic Bug Report'; |
||
73 | $mail->setFrom('[email protected]'); |
||
74 | $mail->Body = $message; |
||
75 | foreach (BUG_REPORT_TO_ADDRESSES as $toAddress) { |
||
76 | $mail->addAddress($toAddress); |
||
77 | } |
||
78 | $mail->send(); |
||
79 | } |
||
80 | |||
81 | return $errorType; |
||
82 | } |
||
179 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.