Completed
Push — master ( d49014...393727 )
by Vincenzo
02:54
created

Player   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 0 Features 3
Metric Value
wmc 6
c 7
b 0
f 3
lcom 1
cbo 1
dl 0
loc 70
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A team() 0 4 1
A goals() 0 6 1
A lastMatches() 0 6 1
A appearances() 0 6 1
A avg() 0 6 1
A scopeStatistics() 0 10 1
1
<?php
2
3
namespace App\Lib\DsManager\Models\Orm;
4
5
/**
6
 * Class Player
7
 * @package App\Lib\DsManager\Models
8
 */
9
class Player extends DsManagerOrm
10
{
11
12
    /**
13
     * @var string
14
     */
15
    protected $table = 'players';
16
17
    /**
18
     * @var array
19
     */
20
    protected $fillable = [
21
        'name',
22
        'surname',
23
        'age',
24
        'nationality',
25
        'skillAvg',
26
        'wageReq',
27
        'val',
28
        'role',
29
        'team_id'
30
    ];
31
32
    /**
33
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34
     */
35
    public function team()
36
    {
37
        return $this->belongsTo(Team::class);
38
    }
39
40
    public function lastMatches()
41
    {
42
        return $this->hasMany(MatchPlayer::class)
43
            ->orderBy('updated_at', 'DESC')
44
            ->limit(5);
45
    }
46
47
    public function goals()
48
    {
49
        return $this->hasOne(MatchPlayer::class)
50
            ->selectRaw('player_id, sum(goals) as count')
51
            ->groupBy('player_id');
52
    }
53
54
    public function appearances()
55
    {
56
        return $this->hasOne(MatchPlayer::class)
57
            ->selectRaw('player_id, count(match_id) as count')
58
            ->groupBy('player_id');
59
    }
60
61
    public function avg()
62
    {
63
        return $this->hasOne(MatchPlayer::class)
64
            ->selectRaw('player_id, round(avg(vote),2) as avg')
65
            ->groupBy('player_id');
66
    }
67
68
    public function scopeStatistics($query)
69
    {
70
        return $query->with(
71
            'goals',
72
            'appearances',
73
            'avg',
74
            'lastMatches',
75
            'team'
76
        );
77
    }
78
}