Leaderboard   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findByGameId() 0 3 1
A scoreSumRankRewards() 0 3 1
A timescopes() 0 3 1
A getCurrentTimescopeAttribute() 0 3 1
A highscoreRankRewards() 0 3 1
A scoreSumRewards() 0 3 1
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
}