We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Total Complexity | 4 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
8 | class UserRanking { |
||
9 | |||
10 | const NAMES = [ |
||
11 | 1 => 'Newbie', |
||
12 | 2 => 'Beginner', |
||
13 | 3 => 'Fledgling', |
||
14 | 4 => 'Average', |
||
15 | 5 => 'Adept', |
||
16 | 6 => 'Expert', |
||
17 | 7 => 'Elite', |
||
18 | 8 => 'Master', |
||
19 | 9 => 'Grandmaster', |
||
20 | ]; |
||
21 | |||
22 | const MIN_RANK = 1; |
||
23 | const MAX_RANK = 9; |
||
24 | |||
25 | const SCORE_POW = .3; |
||
26 | const SCORE_POW_RANK_INCREMENT = 5.2; |
||
27 | |||
28 | /** |
||
29 | * Given a score, return the associated rank |
||
30 | */ |
||
31 | public static function getRankFromScore(int $score) : int { |
||
32 | $rank = ICeil(pow($score, self::SCORE_POW) / self::SCORE_POW_RANK_INCREMENT); |
||
33 | $rank = min(max($rank, self::MIN_RANK), self::MAX_RANK); |
||
34 | return $rank; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Given a rank, return the minimum score needed to achieve it |
||
39 | * (this is an inversion of getRankFromScore) |
||
40 | */ |
||
41 | public static function getMinScoreForRank(int $rank) : int { |
||
42 | return ICeil(pow(($rank - 1) * self::SCORE_POW_RANK_INCREMENT, 1 / self::SCORE_POW)); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Return the title associated with the given rank |
||
47 | */ |
||
48 | public static function getName(int $rank) : string { |
||
50 | } |
||
51 | |||
52 | public static function getAllNames() : array { |
||
54 | } |
||
55 | |||
57 |