Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
32 / 32 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| RatingBounds | |
100.00% |
32 / 32 |
|
100.00% |
8 / 8 |
18 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getConditions | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| addSqlConditions | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| addQueryConditions | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| textualDescription | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| coverRank | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| fromRanks | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| containsRating | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | class RatingBounds |
| 4 | { |
| 5 | public function __construct(?float $min = null, ?float $max = null) |
| 6 | { |
| 7 | $this->min = $min; |
| 8 | $this->max = $max; |
| 9 | } |
| 10 | |
| 11 | public function getConditions(): array |
| 12 | { |
| 13 | $result = []; |
| 14 | if ($this->min) |
| 15 | $result['rating >= '] = $this->min; |
| 16 | if ($this->max) |
| 17 | $result['rating < '] = $this->max; |
| 18 | return $result; |
| 19 | } |
| 20 | |
| 21 | public function addSqlConditions(string &$condition): string |
| 22 | { |
| 23 | if ($this->min) |
| 24 | Util::addSqlCondition($condition, "tsumego.rating >= " . $this->min); |
| 25 | if ($this->max) |
| 26 | Util::addSqlCondition($condition, "tsumego.rating < " . $this->max); |
| 27 | return $condition; |
| 28 | } |
| 29 | |
| 30 | public function addQueryConditions(Query $query): void |
| 31 | { |
| 32 | if ($this->min) |
| 33 | $query->conditions[] = 'tsumego.rating >= ' . $this->min; |
| 34 | if ($this->max) |
| 35 | $query->conditions[] = 'tsumego.rating < ' . $this->max; |
| 36 | } |
| 37 | |
| 38 | public function textualDescription(): string |
| 39 | { |
| 40 | $result = ''; |
| 41 | if ($this->min) |
| 42 | $result .= ' from ' . $this->min; |
| 43 | if ($this->max) |
| 44 | $result .= ' to ' . $this->max; |
| 45 | return $result; |
| 46 | } |
| 47 | |
| 48 | public static function coverRank(string $rank, ?string $minimalRank = null): RatingBounds |
| 49 | { |
| 50 | $result = new RatingBounds(); |
| 51 | if ($rank != $minimalRank) |
| 52 | $result->min = Rating::getRankMinimalRatingFromReadableRank($rank); |
| 53 | $result->max = Rating::getRankMinimalRating(Rating::getRankFromReadableRank($rank) + 1); |
| 54 | return $result; |
| 55 | } |
| 56 | |
| 57 | public static function fromRanks(string $readableMin, string $readableMax): RatingBounds |
| 58 | { |
| 59 | return new RatingBounds( |
| 60 | Rating::getRankMinimalRatingFromReadableRank($readableMin), |
| 61 | Rating::getRankMinimalRatingFromReadableRank($readableMax)); |
| 62 | } |
| 63 | |
| 64 | public function containsRating(float $rating) |
| 65 | { |
| 66 | return $rating >= $this->min && $rating < $this->max; |
| 67 | } |
| 68 | |
| 69 | public ?float $min = null; |
| 70 | public ?float $max = null; |
| 71 | } |