Leaderboard::findByGameId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Furic\Leaderboards\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Furic\Leaderboards\Models\LeaderboardTimescope;
7
8
class Leaderboard extends Model
9
{
10
11
    protected $guarded = [];
12
13
    protected $appends = ['currentTimescope'];
14
15
    public static function findByGameId($gameId)
16
    {
17
        return SELF::where('game_id', $gameId)->firstOrFail();
18
    }
19
20
    public function timescopes()
21
    {
22
        return $this->hasMany(LeaderboardTimescope::class);
23
    }
24
25
    public function scoreSumRewards()
26
    {
27
        return $this->hasMany(LeaderboardReward::class)->whereNotNull('score_sum')->orderBy('score_sum', 'desc')->get();
28
    }
29
    
30
    public function scoreSumRankRewards()
31
    {
32
        return $this->hasMany(LeaderboardReward::class)->whereNotNull('score_sum_rank')->orderBy('score_sum_rank')->get();
33
    }
34
    
35
    public function highscoreRankRewards()
36
    {
37
        return $this->hasMany(LeaderboardReward::class)->whereNotNull('highscore_rank')->orderBy('highscore_rank')->get();
38
    }
39
40
    public function getCurrentTimescopeAttribute()
41
    {
42
        return LeaderboardTimescope::findByLeaderboard($this);
43
    }
44
45
}