We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 18 |
| Paths | > 20000 |
| Total Lines | 66 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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); |
||
| 17 | public function build(AbstractSmrPlayer $player): never { |
||
| 18 | $alliance_id = $this->allianceID; |
||
| 19 | |||
| 20 | if (Request::has('description')) { |
||
| 21 | $description = Request::get('description'); |
||
| 22 | } |
||
| 23 | if (Request::has('discord_server')) { |
||
| 24 | $discordServer = Request::get('discord_server'); |
||
| 25 | } |
||
| 26 | if (Request::has('discord_channel')) { |
||
| 27 | $discordChannel = Request::get('discord_channel'); |
||
| 28 | } |
||
| 29 | if (Request::has('irc')) { |
||
| 30 | $irc = Request::get('irc'); |
||
| 31 | } |
||
| 32 | if (Request::has('mod')) { |
||
| 33 | $mod = Request::get('mod'); |
||
| 34 | } |
||
| 35 | if (Request::has('url')) { |
||
| 36 | $url = Request::get('url'); |
||
| 37 | } |
||
| 38 | |||
| 39 | // Prevent XSS attacks |
||
| 40 | if (isset($url) && preg_match('/"/', $url)) { |
||
| 41 | create_error('You cannot use a " in the image link!'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $alliance = SmrAlliance::getAlliance($alliance_id, $player->getGameID()); |
||
| 45 | if (Request::has('recruit_type')) { |
||
| 46 | $recruitType = Request::get('recruit_type'); |
||
| 47 | $password = Request::get('password', ''); |
||
| 48 | $alliance->setRecruitType($recruitType, $password); |
||
| 49 | } |
||
| 50 | if (isset($description)) { |
||
| 51 | $alliance->setAllianceDescription($description, $player); |
||
| 52 | } |
||
| 53 | if (isset($discordServer)) { |
||
| 54 | $alliance->setDiscordServer($discordServer); |
||
| 55 | } |
||
| 56 | if (isset($discordChannel)) { |
||
| 57 | if (empty($discordChannel)) { |
||
| 58 | $alliance->setDiscordChannel(null); |
||
| 59 | } else { |
||
| 60 | // no duplicates in a given game |
||
| 61 | $db = Database::getInstance(); |
||
| 62 | $dbResult = $db->read('SELECT 1 FROM alliance WHERE discord_channel =' . $db->escapeString($discordChannel) . ' AND game_id = ' . $db->escapeNumber($alliance->getGameID()) . ' AND alliance_id != ' . $db->escapeNumber($alliance->getAllianceID()) . ' LIMIT 1'); |
||
| 63 | if ($dbResult->hasRecord()) { |
||
| 64 | create_error('Another alliance is already using that Discord Channel ID!'); |
||
| 65 | } |
||
| 66 | |||
| 67 | $alliance->setDiscordChannel($discordChannel); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | if (isset($irc)) { |
||
| 71 | $alliance->setIrcChannel($irc); |
||
| 72 | } |
||
| 73 | if (isset($mod)) { |
||
| 74 | $alliance->setMotD($mod); |
||
| 75 | } |
||
| 76 | if (isset($url)) { |
||
| 77 | $alliance->setImageURL($url); |
||
| 78 | } |
||
| 79 | |||
| 80 | $alliance->update(); |
||
| 81 | $container = new AllianceRoster($alliance_id); |
||
| 82 | $container->go(); |
||
| 83 | } |
||
| 86 |