We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 2 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 8 | enum UserRanking: int { |
||
| 9 | |||
| 10 | // Backing values map to database values and must not be changed |
||
| 11 | case Newbie = 1; |
||
| 12 | case Beginner = 2; |
||
| 13 | case Fledgling = 3; |
||
| 14 | case Average = 4; |
||
| 15 | case Adept = 5; |
||
| 16 | case Expert = 6; |
||
| 17 | case Elite = 7; |
||
| 18 | case Master = 8; |
||
| 19 | case Grandmaster = 9; |
||
| 20 | |||
| 21 | public const MIN_RANK = 1; |
||
| 22 | public const MAX_RANK = 9; |
||
| 23 | |||
| 24 | public const SCORE_POW = .3; |
||
| 25 | public const SCORE_POW_RANK_INCREMENT = 5.2; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Given a score, return the associated rank |
||
| 29 | */ |
||
| 30 | public static function getRankFromScore(int $score): self { |
||
| 31 | $rank = ICeil(pow($score, self::SCORE_POW) / self::SCORE_POW_RANK_INCREMENT); |
||
| 32 | $rank = min(max($rank, self::MIN_RANK), self::MAX_RANK); |
||
| 33 | return self::from($rank); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Given a rank, return the minimum score needed to achieve it |
||
| 38 | * (this is an inversion of getRankFromScore) |
||
| 39 | */ |
||
| 40 | public function getMinScore(): int { |
||
| 42 | } |
||
| 43 | |||
| 45 |