Skip to content

Commit

Permalink
Merge pull request #10867 from nanaya/score-rank-enum
Browse files Browse the repository at this point in the history
Convert ScoreRank to enum
  • Loading branch information
notbakaneko authored Jan 16, 2024
2 parents 48f231e + 347e1fd commit 48d63ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
19 changes: 19 additions & 0 deletions app/Enums/ScoreRank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

namespace App\Enums;

enum ScoreRank: string
{
case A = 'A';
case B = 'B';
case C = 'C';
case D = 'D';
case F = 'F';
case S = 'S';
case SH = 'SH';
case X = 'X';
case XH = 'XH';
}
16 changes: 0 additions & 16 deletions app/Libraries/ScoreRank.php

This file was deleted.

4 changes: 2 additions & 2 deletions app/Models/Solo/ScoreData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace App\Models\Solo;

use App\Enums\ScoreRank;
use App\Exceptions\InvariantException;
use App\Libraries\ScoreRank;
use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use JsonSerializable;
Expand Down Expand Up @@ -103,7 +103,7 @@ public function set($model, $key, $value, $attributes)

public function assertCompleted(): void
{
if (!ScoreRank::isValid($this->rank)) {
if (ScoreRank::tryFrom($this->rank) === null) {
throw new InvariantException("'{$this->rank}' is not a valid rank.");
}

Expand Down

0 comments on commit 48d63ae

Please sign in to comment.