smrealms /
smr
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php declare(strict_types=1); |
||||
| 2 | |||||
| 3 | namespace Smr; |
||||
| 4 | |||||
| 5 | /** |
||||
| 6 | * User ranking titles |
||||
| 7 | */ |
||||
| 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); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 32 | $rank = min(max($rank, self::MIN_RANK), self::MAX_RANK); |
||||
|
0 ignored issues
–
show
|
|||||
| 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 { |
||||
| 41 | return ICeil(pow(($this->value - 1) * self::SCORE_POW_RANK_INCREMENT, 1 / self::SCORE_POW)); |
||||
|
0 ignored issues
–
show
The function
ICeil was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 42 | } |
||||
| 43 | |||||
| 44 | } |
||||
| 45 |