Complex classes like Player 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 Player, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Player extends AvatarModel implements NamedModel, DuplexUrlInterface, EloInterface |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * These are built-in roles that cannot be deleted via the web interface so we will be storing these values as |
||
| 21 | * constant variables. Hopefully, a user won't be silly enough to delete them manually from the database. |
||
| 22 | * |
||
| 23 | * @TODO Deprecate these and use the Role constants |
||
| 24 | */ |
||
| 25 | const DEVELOPER = Role::DEVELOPER; |
||
| 26 | const ADMIN = Role::ADMINISTRATOR; |
||
| 27 | const COP = Role::COP; |
||
| 28 | const REFEREE = Role::REFEREE; |
||
| 29 | const S_ADMIN = Role::SYSADMIN; |
||
| 30 | const PLAYER = Role::PLAYER; |
||
| 31 | const PLAYER_NO_PM = Role::PLAYER_NO_PM; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The bzid of the player |
||
| 35 | * @var int |
||
| 36 | */ |
||
| 37 | protected $bzid; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The id of the player's team |
||
| 41 | * @var int |
||
| 42 | */ |
||
| 43 | protected $team; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The player's e-mail address |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $email; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Whether the player has verified their e-mail address |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $verified; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * What kind of events the player should be e-mailed about |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $receives; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * A confirmation code for the player's e-mail address verification |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $confirmCode; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Whether the callsign of the player is outdated |
||
| 71 | * @var bool |
||
| 72 | */ |
||
| 73 | protected $outdated; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * The player's profile description |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | protected $description; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The id of the player's country |
||
| 83 | * @var int |
||
| 84 | */ |
||
| 85 | protected $country; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The site theme this player has chosen |
||
| 89 | * @var string |
||
| 90 | */ |
||
| 91 | protected $theme; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Whether or not this player has opted-in for color blindness assistance. |
||
| 95 | * @var bool |
||
| 96 | */ |
||
| 97 | protected $color_blind_enabled; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The player's timezone PHP identifier, e.g. "Europe/Paris" |
||
| 101 | * @var string |
||
| 102 | */ |
||
| 103 | protected $timezone; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The date the player joined the site |
||
| 107 | * @var TimeDate |
||
| 108 | */ |
||
| 109 | protected $joined; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * The date of the player's last login |
||
| 113 | * @var TimeDate |
||
| 114 | */ |
||
| 115 | protected $last_login; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The date of the player's last match |
||
| 119 | * @var Match |
||
| 120 | */ |
||
| 121 | protected $last_match; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * The roles a player belongs to |
||
| 125 | * @var Role[] |
||
| 126 | */ |
||
| 127 | protected $roles; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The permissions a player has |
||
| 131 | * @var Permission[] |
||
| 132 | */ |
||
| 133 | protected $permissions; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * A section for admins to write notes about players |
||
| 137 | * @var string |
||
| 138 | */ |
||
| 139 | protected $admin_notes; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The ban of the player, or null if the player is not banned |
||
| 143 | * @var Ban|null |
||
| 144 | */ |
||
| 145 | protected $ban; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Cached results for match summaries |
||
| 149 | * |
||
| 150 | * @var array |
||
| 151 | */ |
||
| 152 | private $cachedMatchSummary; |
||
| 153 | |||
| 154 | /** |
||
| 155 | * The cached match count for a player |
||
| 156 | * |
||
| 157 | * @var int |
||
| 158 | */ |
||
| 159 | private $cachedMatchCount = null; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The Elo for this player that has been explicitly set for this player from a database query. This value will take |
||
| 163 | * precedence over having to build to an Elo season history. |
||
| 164 | * |
||
| 165 | * @var int |
||
| 166 | */ |
||
| 167 | private $elo; |
||
| 168 | private $eloSeason; |
||
| 169 | private $eloSeasonHistory; |
||
| 170 | |||
| 171 | private $matchActivity; |
||
| 172 | |||
| 173 | private $is_disabled; |
||
| 174 | |||
| 175 | const DELETED_COLUMN = 'is_deleted'; |
||
| 176 | const TABLE = "players"; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * The location where avatars will be stored |
||
| 180 | */ |
||
| 181 | const AVATAR_LOCATION = "/web/assets/imgs/avatars/players/"; |
||
| 182 | |||
| 183 | const EDIT_PERMISSION = Permission::EDIT_USER; |
||
| 184 | const SOFT_DELETE_PERMISSION = Permission::SOFT_DELETE_USER; |
||
| 185 | const HARD_DELETE_PERMISSION = Permission::HARD_DELETE_USER; |
||
| 186 | |||
| 187 | /** |
||
| 188 | * {@inheritdoc} |
||
| 189 | */ |
||
| 190 | protected function assignResult($player) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | protected function assignLazyResult($player) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Add a player a new role |
||
| 244 | * |
||
| 245 | * @param Role|int $role_id The role ID to add a player to |
||
| 246 | * |
||
| 247 | * @return bool Whether the operation was successful or not |
||
| 248 | */ |
||
| 249 | public function addRole($role_id) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Get the notes admins have left about a player |
||
| 272 | * @return string The notes |
||
| 273 | */ |
||
| 274 | public function getAdminNotes() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Get the player's BZID |
||
| 283 | * @return int The BZID |
||
| 284 | */ |
||
| 285 | public function getBZID() |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Get the country a player belongs to |
||
| 292 | * |
||
| 293 | * @return Country The country belongs to |
||
| 294 | */ |
||
| 295 | public function getCountry() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Get the e-mail address of the player |
||
| 302 | * |
||
| 303 | * @return string The address |
||
| 304 | */ |
||
| 305 | public function getEmailAddress() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Build a key that we'll use for caching season Elo data in this model |
||
| 314 | * |
||
| 315 | * @param string|null $season The season to get |
||
| 316 | * @param int|null $year The year of the season to get |
||
| 317 | * |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | private function buildSeasonKey(&$season, &$year) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Build a key to use for caching season Elo data in this model from a timestamp |
||
| 335 | * |
||
| 336 | * @param DateTime $timestamp |
||
| 337 | * |
||
| 338 | * @return string |
||
| 339 | */ |
||
| 340 | private function buildSeasonKeyFromTimestamp(\DateTime $timestamp) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Remove all Elo data for this model for matches occurring after the given match (inclusive) |
||
| 349 | * |
||
| 350 | * This function will not remove the Elo data for this match from the database. Ideally, this function should only |
||
| 351 | * be called during Elo recalculation for this match. |
||
| 352 | * |
||
| 353 | * @internal |
||
| 354 | * |
||
| 355 | * @param Match $match |
||
| 356 | * |
||
| 357 | * @see Match::recalculateElo() |
||
| 358 | */ |
||
| 359 | public function invalidateMatchFromCache(Match $match) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Get the Elo changes for a player for a given season |
||
| 380 | * |
||
| 381 | * @param string|null $season The season to get |
||
| 382 | * @param int|null $year The year of the season to get |
||
| 383 | * |
||
| 384 | * @return array |
||
| 385 | */ |
||
| 386 | public function getEloSeasonHistory($season = null, $year = null) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get the player's Elo for a season. |
||
| 424 | * |
||
| 425 | * With the default arguments, it will fetch the Elo for the current season. |
||
| 426 | * |
||
| 427 | * @param string|null $season The season we're looking for: winter, spring, summer, or fall |
||
| 428 | * @param int|null $year The year of the season we're looking for |
||
| 429 | * |
||
| 430 | * @return int The player's Elo |
||
| 431 | */ |
||
| 432 | public function getElo($season = null, $year = null) |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Adjust the Elo of a player for the current season based on a Match |
||
| 460 | * |
||
| 461 | * **Warning:** If $match is null, the Elo for the player will be modified but the value will not be persisted to |
||
| 462 | * the database. |
||
| 463 | * |
||
| 464 | * @param int $adjust The value to be added to the current ELO (negative to subtract) |
||
| 465 | * @param Match|null $match The match where this Elo change took place |
||
| 466 | */ |
||
| 467 | public function adjustElo($adjust, Match $match = null) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Returns whether the player has verified their e-mail address |
||
| 495 | * |
||
| 496 | * @return bool `true` for verified players |
||
| 497 | */ |
||
| 498 | public function isVerified() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * Returns the confirmation code for the player's e-mail address verification |
||
| 507 | * |
||
| 508 | * @return string The player's confirmation code |
||
| 509 | */ |
||
| 510 | public function getConfirmCode() |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Returns what kind of events the player should be e-mailed about |
||
| 519 | * |
||
| 520 | * @return string The type of notifications |
||
| 521 | */ |
||
| 522 | public function getReceives() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Finds out whether the specified player wants and can receive an e-mail |
||
| 531 | * message |
||
| 532 | * |
||
| 533 | * @param string $type |
||
| 534 | * @return bool `true` if the player should be sent an e-mail |
||
| 535 | */ |
||
| 536 | public function canReceive($type) |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Find out whether the specified confirmation code is correct |
||
| 554 | * |
||
| 555 | * This method protects against timing attacks |
||
| 556 | * |
||
| 557 | * @param string $code The confirmation code to check |
||
| 558 | * @return bool `true` for a correct e-mail verification code |
||
| 559 | */ |
||
| 560 | public function isCorrectConfirmCode($code) |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Get the player's sanitized description |
||
| 573 | * @return string The description |
||
| 574 | */ |
||
| 575 | public function getDescription() |
||
| 581 | |||
| 582 | /** |
||
| 583 | * Get the joined date of the player |
||
| 584 | * @return TimeDate The joined date of the player |
||
| 585 | */ |
||
| 586 | public function getJoinedDate() |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Get all of the known IPs used by the player |
||
| 595 | * |
||
| 596 | * @return string[][] An array containing IPs and hosts |
||
| 597 | */ |
||
| 598 | public function getKnownIPs() |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Get the last login for a player |
||
| 608 | * @return TimeDate The date of the last login |
||
| 609 | */ |
||
| 610 | public function getLastLogin() |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Get the last match |
||
| 619 | * @return Match |
||
| 620 | */ |
||
| 621 | public function getLastMatch() |
||
| 627 | |||
| 628 | /** |
||
| 629 | * Get all of the callsigns a player has used to log in to the website |
||
| 630 | * @return string[] An array containing all of the past callsigns recorded for a player |
||
| 631 | */ |
||
| 632 | public function getPastCallsigns() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Get the player's team |
||
| 639 | * @return Team The object representing the team |
||
| 640 | */ |
||
| 641 | public function getTeam() |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Get the player's timezone PHP identifier (example: "Europe/Paris") |
||
| 648 | * @return string The timezone |
||
| 649 | */ |
||
| 650 | public function getTimezone() |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Get the roles of the player |
||
| 659 | * @return Role[] |
||
| 660 | */ |
||
| 661 | public function getRoles() |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Rebuild the list of permissions a user has been granted |
||
| 670 | */ |
||
| 671 | private function updateUserPermissions() |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Check if a player has a specific permission |
||
| 683 | * |
||
| 684 | * @param string|null $permission The permission to check for |
||
| 685 | * |
||
| 686 | * @return bool Whether or not the player has the permission |
||
| 687 | */ |
||
| 688 | public function hasPermission($permission) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Check whether or not a player been in a match or has logged on in the specified amount of time to be considered |
||
| 701 | * active |
||
| 702 | * |
||
| 703 | * @return bool True if the player has been active |
||
| 704 | */ |
||
| 705 | public function hasBeenActive() |
||
| 721 | |||
| 722 | /** |
||
| 723 | * Check whether the callsign of the player is outdated |
||
| 724 | * |
||
| 725 | * Returns true if this player has probably changed their callsign, making |
||
| 726 | * the current username stored in the database obsolete |
||
| 727 | * |
||
| 728 | * @return bool Whether or not the player is disabled |
||
| 729 | */ |
||
| 730 | public function isOutdated() |
||
| 736 | |||
| 737 | /** |
||
| 738 | * Check if a player's account has been disabled |
||
| 739 | * |
||
| 740 | * @return bool Whether or not the player is disabled |
||
| 741 | */ |
||
| 742 | public function isDisabled() |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Check if everyone can log in as this user on a test environment |
||
| 749 | * |
||
| 750 | * @return bool |
||
| 751 | */ |
||
| 752 | public function isTestUser() |
||
| 756 | |||
| 757 | /** |
||
| 758 | * Check if a player is teamless |
||
| 759 | * |
||
| 760 | * @return bool True if the player is teamless |
||
| 761 | */ |
||
| 762 | public function isTeamless() |
||
| 766 | |||
| 767 | /** |
||
| 768 | * Mark a player's account as banned |
||
| 769 | * |
||
| 770 | * @deprecated The players table shouldn't have any indicators of banned status, the Bans table is the authoritative source |
||
| 771 | */ |
||
| 772 | public function markAsBanned() |
||
| 776 | |||
| 777 | /** |
||
| 778 | * Mark a player's account as unbanned |
||
| 779 | * |
||
| 780 | * @deprecated The players table shouldn't have any indicators of banned status, the Bans table is the authoritative source |
||
| 781 | */ |
||
| 782 | public function markAsUnbanned() |
||
| 786 | |||
| 787 | /** |
||
| 788 | * Find out if a player is hard banned |
||
| 789 | * |
||
| 790 | * @return bool |
||
| 791 | */ |
||
| 792 | public function isBanned() |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Get the ban of the player |
||
| 801 | * |
||
| 802 | * This method performs a load of all the lazy parameters of the Player |
||
| 803 | * |
||
| 804 | * @return Ban|null The current ban of the player, or null if the player is |
||
| 805 | * is not banned |
||
| 806 | */ |
||
| 807 | public function getBan() |
||
| 813 | |||
| 814 | /** |
||
| 815 | * Remove a player from a role |
||
| 816 | * |
||
| 817 | * @param int $role_id The role ID to add or remove |
||
| 818 | * |
||
| 819 | * @return bool Whether the operation was successful or not |
||
| 820 | */ |
||
| 821 | public function removeRole($role_id) |
||
| 828 | |||
| 829 | /** |
||
| 830 | * Set the player's email address and reset their verification status |
||
| 831 | * @param string $email The address |
||
| 832 | */ |
||
| 833 | public function setEmailAddress($email) |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Set whether the player has verified their e-mail address |
||
| 850 | * |
||
| 851 | * @param bool $verified Whether the player is verified or not |
||
| 852 | * @return self |
||
| 853 | */ |
||
| 854 | public function setVerified($verified) |
||
| 864 | |||
| 865 | /** |
||
| 866 | * Generate a new random confirmation token for e-mail address verification |
||
| 867 | * |
||
| 868 | * @return self |
||
| 869 | */ |
||
| 870 | public function generateNewConfirmCode() |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Set the confirmation token for e-mail address verification |
||
| 880 | * |
||
| 881 | * @param string $code The confirmation code |
||
| 882 | * @return self |
||
| 883 | */ |
||
| 884 | private function setConfirmCode($code) |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Set what kind of events the player should be e-mailed about |
||
| 893 | * |
||
| 894 | * @param string $receives The type of notification |
||
| 895 | * @return self |
||
| 896 | */ |
||
| 897 | public function setReceives($receives) |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Set whether the callsign of the player is outdated |
||
| 906 | * |
||
| 907 | * @param bool $outdated Whether the callsign is outdated |
||
| 908 | * @return self |
||
| 909 | */ |
||
| 910 | public function setOutdated($outdated) |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Set the player's description |
||
| 919 | * @param string $description The description |
||
| 920 | */ |
||
| 921 | public function setDescription($description) |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Set the player's timezone |
||
| 928 | * @param string $timezone The timezone |
||
| 929 | */ |
||
| 930 | public function setTimezone($timezone) |
||
| 934 | |||
| 935 | /** |
||
| 936 | * Set the player's team |
||
| 937 | * @param int $team The team's ID |
||
| 938 | */ |
||
| 939 | public function setTeam($team) |
||
| 943 | |||
| 944 | /** |
||
| 945 | * Set the match the player last participated in |
||
| 946 | * |
||
| 947 | * @param int $match The match's ID |
||
| 948 | */ |
||
| 949 | public function setLastMatch($match) |
||
| 953 | |||
| 954 | /** |
||
| 955 | * Set the player's status |
||
| 956 | * @param string $status The new status |
||
| 957 | */ |
||
| 958 | public function setStatus($status) |
||
| 962 | |||
| 963 | /** |
||
| 964 | * Set the player's admin notes |
||
| 965 | * @param string $admin_notes The new admin notes |
||
| 966 | * @return self |
||
| 967 | */ |
||
| 968 | public function setAdminNotes($admin_notes) |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Set the player's country |
||
| 975 | * @param int $country The ID of the new country |
||
| 976 | * @return self |
||
| 977 | */ |
||
| 978 | public function setCountry($country) |
||
| 982 | |||
| 983 | /** |
||
| 984 | * Get the player's chosen theme preference |
||
| 985 | * |
||
| 986 | * @return string |
||
| 987 | */ |
||
| 988 | public function getTheme() |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Set the site theme for the player |
||
| 997 | * |
||
| 998 | * If the chosen site theme is invalid, it'll be defaulted to the site default (the first theme defined) |
||
| 999 | * |
||
| 1000 | * @param string $theme |
||
| 1001 | */ |
||
| 1002 | public function setTheme($theme) |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Whether or not this player has color blind assistance enabled. |
||
| 1015 | * |
||
| 1016 | * @return bool |
||
| 1017 | */ |
||
| 1018 | public function hasColorBlindAssist() |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Set a player's setting for color blind assistance. |
||
| 1027 | * |
||
| 1028 | * @param bool $enabled |
||
| 1029 | * |
||
| 1030 | * @return self |
||
| 1031 | */ |
||
| 1032 | public function setColorBlindAssist($enabled) |
||
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Updates this player's last login |
||
| 1039 | */ |
||
| 1040 | public function updateLastLogin() |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Get the player's username |
||
| 1047 | * @return string The username |
||
| 1048 | */ |
||
| 1049 | public function getUsername() |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Get the player's username, safe for use in your HTML |
||
| 1056 | * @return string The username |
||
| 1057 | */ |
||
| 1058 | public function getEscapedUsername() |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Alias for Player::setUsername() |
||
| 1065 | * |
||
| 1066 | * @param string $username The new username |
||
| 1067 | * @return self |
||
| 1068 | */ |
||
| 1069 | public function setName($username) |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Mark all the unread messages of a player as read |
||
| 1076 | * |
||
| 1077 | * @return void |
||
| 1078 | */ |
||
| 1079 | public function markMessagesAsRead() |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Set the roles of a user |
||
| 1089 | * |
||
| 1090 | * @todo Is it worth making this faster? |
||
| 1091 | * @param Role[] $roles The new roles of the user |
||
| 1092 | * @return self |
||
| 1093 | */ |
||
| 1094 | public function setRoles($roles) |
||
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Give or remove a role to/form a player |
||
| 1120 | * |
||
| 1121 | * @param int $role_id The role ID to add or remove |
||
| 1122 | * @param string $action Whether to "add" or "remove" a role for a player |
||
| 1123 | * |
||
| 1124 | * @return bool Whether the operation was successful or not |
||
| 1125 | */ |
||
| 1126 | private function modifyRole($role_id, $action) |
||
| 1144 | |||
| 1145 | /** |
||
| 1146 | * Given a player's BZID, get a player object |
||
| 1147 | * |
||
| 1148 | * @param int $bzid The player's BZID |
||
| 1149 | * @return Player |
||
| 1150 | */ |
||
| 1151 | public static function getFromBZID($bzid) |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Get a single player by their username |
||
| 1158 | * |
||
| 1159 | * @param string $username The username to look for |
||
| 1160 | * @return Player |
||
| 1161 | */ |
||
| 1162 | public static function getFromUsername($username) |
||
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Get all the players in the database that have an active status |
||
| 1171 | * @return Player[] An array of player BZIDs |
||
| 1172 | */ |
||
| 1173 | public static function getPlayers() |
||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Show the number of notifications the user hasn't read yet |
||
| 1182 | * @return int |
||
| 1183 | */ |
||
| 1184 | public function countUnreadNotifications() |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Count the number of matches a player has participated in |
||
| 1191 | * @return int |
||
| 1192 | */ |
||
| 1193 | public function getMatchCount() |
||
| 1204 | |||
| 1205 | /** |
||
| 1206 | * Get the (victory/total matches) ratio of the player |
||
| 1207 | * @return float |
||
| 1208 | */ |
||
| 1209 | public function getMatchWinRatio() |
||
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Get the (total caps made by team/total matches) ratio of the player |
||
| 1227 | * @return float |
||
| 1228 | */ |
||
| 1229 | public function getMatchAverageCaps() |
||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Get the match activity in matches per day for a player |
||
| 1256 | * |
||
| 1257 | * @return float |
||
| 1258 | */ |
||
| 1259 | public function getMatchActivity() |
||
| 1279 | |||
| 1280 | /** |
||
| 1281 | * Return an array of matches this player participated in per month. |
||
| 1282 | * |
||
| 1283 | * ``` |
||
| 1284 | * ['yyyy-mm'] = <number of matches> |
||
| 1285 | * ``` |
||
| 1286 | * |
||
| 1287 | * @param TimeDate|string $timePeriod |
||
| 1288 | * |
||
| 1289 | * @return int[] |
||
| 1290 | */ |
||
| 1291 | public function getMatchSummary($timePeriod = '1 year ago') |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Show the number of messages the user hasn't read yet |
||
| 1309 | * @return int |
||
| 1310 | */ |
||
| 1311 | public function countUnreadMessages() |
||
| 1317 | |||
| 1318 | /** |
||
| 1319 | * Get all of the members belonging to a team |
||
| 1320 | * @param int $teamID The ID of the team to fetch the members of |
||
| 1321 | * @return Player[] An array of Player objects of the team members |
||
| 1322 | */ |
||
| 1323 | public static function getTeamMembers($teamID) |
||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * {@inheritdoc} |
||
| 1332 | */ |
||
| 1333 | public static function getActiveStatuses() |
||
| 1337 | |||
| 1338 | /** |
||
| 1339 | * {@inheritdoc} |
||
| 1340 | */ |
||
| 1341 | public static function getEagerColumns($prefix = null) |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * {@inheritdoc} |
||
| 1359 | */ |
||
| 1360 | public static function getLazyColumns($prefix = null) |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * {@inheritdoc} |
||
| 1383 | */ |
||
| 1384 | public static function getEagerColumnsList() |
||
| 1398 | |||
| 1399 | /** |
||
| 1400 | * {@inheritdoc} |
||
| 1401 | */ |
||
| 1402 | public static function getLazyColumnsList() |
||
| 1420 | |||
| 1421 | /** |
||
| 1422 | * Get a query builder for players |
||
| 1423 | * |
||
| 1424 | * @throws Exception |
||
| 1425 | * |
||
| 1426 | * @return PlayerQueryBuilder |
||
| 1427 | */ |
||
| 1428 | public static function getQueryBuilder() |
||
| 1434 | |||
| 1435 | /** |
||
| 1436 | * Enter a new player to the database |
||
| 1437 | * @param int $bzid The player's bzid |
||
| 1438 | * @param string $username The player's username |
||
| 1439 | * @param int $team The player's team |
||
| 1440 | * @param string $status The player's status |
||
| 1441 | * @param int $role_id The player's role when they are first created |
||
| 1442 | * @param string $avatar The player's profile avatar |
||
| 1443 | * @param string $description The player's profile description |
||
| 1444 | * @param int $country The player's country |
||
| 1445 | * @param string $timezone The player's timezone |
||
| 1446 | * @param string|\TimeDate $joined The date the player joined |
||
| 1447 | * @param string|\TimeDate $last_login The timestamp of the player's last login |
||
| 1448 | * @return Player An object representing the player that was just entered |
||
| 1449 | */ |
||
| 1450 | public static function newPlayer($bzid, $username, $team = null, $status = "active", $role_id = self::PLAYER, $avatar = "", $description = "", $country = 1, $timezone = null, $joined = "now", $last_login = "now") |
||
| 1476 | |||
| 1477 | /** |
||
| 1478 | * Determine if a player exists in the database |
||
| 1479 | * @param int $bzid The player's bzid |
||
| 1480 | * @return bool Whether the player exists in the database |
||
| 1481 | */ |
||
| 1482 | public static function playerBZIDExists($bzid) |
||
| 1486 | |||
| 1487 | /** |
||
| 1488 | * Change a player's callsign and add it to the database if it does not |
||
| 1489 | * exist as a past callsign |
||
| 1490 | * |
||
| 1491 | * @param string $username The new username of the player |
||
| 1492 | * @return self |
||
| 1493 | */ |
||
| 1494 | public function setUsername($username) |
||
| 1525 | |||
| 1526 | /** |
||
| 1527 | * Alphabetical order function for use in usort (case-insensitive) |
||
| 1528 | * @return Closure The sort function |
||
| 1529 | */ |
||
| 1530 | public static function getAlphabeticalSort() |
||
| 1536 | |||
| 1537 | /** |
||
| 1538 | * {@inheritdoc} |
||
| 1539 | * @todo Add a constraint that does this automatically |
||
| 1540 | */ |
||
| 1541 | public function wipe() |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Find whether the player can delete a model |
||
| 1550 | * |
||
| 1551 | * @param PermissionModel $model The model that will be seen |
||
| 1552 | * @param bool $showDeleted Whether to show deleted models to admins |
||
| 1553 | * @return bool |
||
| 1554 | */ |
||
| 1555 | public function canSee($model, $showDeleted = false) |
||
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Find whether the player can delete a model |
||
| 1562 | * |
||
| 1563 | * @param PermissionModel $model The model that will be deleted |
||
| 1564 | * @param bool $hard Whether to check for hard-delete perms, as opposed |
||
| 1565 | * to soft-delete ones |
||
| 1566 | * @return bool |
||
| 1567 | */ |
||
| 1568 | public function canDelete($model, $hard = false) |
||
| 1576 | |||
| 1577 | /** |
||
| 1578 | * Find whether the player can create a model |
||
| 1579 | * |
||
| 1580 | * @param string $modelName The PHP class identifier of the model type |
||
| 1581 | * @return bool |
||
| 1582 | */ |
||
| 1583 | public function canCreate($modelName) |
||
| 1587 | |||
| 1588 | /** |
||
| 1589 | * Find whether the player can edit a model |
||
| 1590 | * |
||
| 1591 | * @param PermissionModel $model The model which will be edited |
||
| 1592 | * @return bool |
||
| 1593 | */ |
||
| 1594 | public function canEdit($model) |
||
| 1598 | } |
||
| 1599 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.