We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 6 |
Paths | 6 |
Total Lines | 62 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 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); |
||
8 | function channel_join($fp, string $rdata): bool { |
||
9 | |||
10 | if (preg_match('/^:(.*)!(.*)@(.*)\sJOIN\s:(.*)\s$/i', $rdata, $msg)) { |
||
11 | |||
12 | $nick = $msg[1]; |
||
13 | $user = $msg[2]; |
||
14 | $host = $msg[3]; |
||
15 | $channel = $msg[4]; |
||
16 | |||
17 | echo_r('[JOIN] ' . $nick . '!' . $user . '@' . $host . ' joined ' . $channel); |
||
18 | |||
19 | $db = Database::getInstance(); |
||
20 | |||
21 | // check if we have seen this user before |
||
22 | $dbResult = $db->read('SELECT * FROM irc_seen WHERE nick = ' . $db->escapeString($nick) . ' AND channel = ' . $db->escapeString($channel)); |
||
23 | |||
24 | if ($dbResult->hasRecord()) { |
||
25 | $dbRecord = $dbResult->record(); |
||
26 | // existing nick? |
||
27 | $seen_id = $dbRecord->getInt('seen_id'); |
||
28 | |||
29 | $seen_count = $dbRecord->getInt('seen_count'); |
||
30 | $seen_by = $dbRecord->getNullableString('seen_by'); |
||
31 | |||
32 | if ($seen_count > 1) { |
||
33 | fwrite($fp, 'PRIVMSG ' . $channel . ' :Welcome back ' . $nick . '. While being away ' . $seen_count . ' players were looking for you, the last one being ' . $seen_by . EOL); |
||
34 | } elseif ($seen_count > 0) { |
||
35 | fwrite($fp, 'PRIVMSG ' . $channel . ' :Welcome back ' . $nick . '. While being away ' . $seen_by . ' was looking for you.' . EOL); |
||
36 | } |
||
37 | |||
38 | $db->write('UPDATE irc_seen |
||
39 | SET signed_on = ' . $db->escapeNumber(time()) . ', |
||
40 | signed_off = 0, |
||
41 | user = ' . $db->escapeString($user) . ', |
||
42 | host = ' . $db->escapeString($host) . ', |
||
43 | seen_count = 0, |
||
44 | seen_by = NULL, |
||
45 | registered = NULL |
||
46 | WHERE seen_id = ' . $db->escapeNumber($seen_id)); |
||
47 | |||
48 | } else { |
||
49 | // new nick? |
||
50 | $db->insert('irc_seen', [ |
||
51 | 'nick' => $db->escapeString($nick), |
||
52 | 'user' => $db->escapeString($user), |
||
53 | 'host' => $db->escapeString($host), |
||
54 | 'channel' => $db->escapeString($channel), |
||
55 | 'signed_on' => $db->escapeNumber(time()), |
||
56 | ]); |
||
57 | |||
58 | if ($nick != IRC_BOT_NICK) { |
||
59 | fwrite($fp, 'PRIVMSG ' . $channel . ' :Welcome, ' . $nick . '! Most players are using Discord (' . DISCORD_URL . ') instead of IRC, but the two platforms are linked by discordbot. Anything you say here will be relayed to the Discord channel and vice versa.' . EOL); |
||
60 | } |
||
61 | } |
||
62 | |||
63 | // check if player joined alliance chat |
||
64 | channel_op_notification($fp, $rdata, $nick, $channel); |
||
65 | |||
66 | return true; |
||
67 | } |
||
68 | |||
69 | return false; |
||
70 | } |
||
109 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.