Test Failed
Push — master ( 051cab...019850 )
by Julien
04:18
created

Competitor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 3
dl 0
loc 84
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A championship() 0 9 1
A category() 0 8 1
A tournament() 0 8 1
A user() 0 4 1
A fightersGroups() 0 4 1
A getName() 0 6 3
1
<?php
2
3
namespace Xoco70\KendoTournaments\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Foundation\Auth\User;
8
use Illuminate\Support\Collection;
9
10
class Competitor extends Model
11
{
12
    use SoftDeletes;
13
    protected $DATES = ['created_at', 'updated_at', 'deleted_at'];
14
15
    protected $table = 'competitor';
16
    public $timestamps = true;
17
    protected $fillable = [
18
        'tournament_category_id',
19
        'user_id',
20
        'confirmed',
21
    ];
22
23
    /**
24
     * Get the Competitor's Championship.
25
     *
26
     * @param $ctId
27
     *
28
     * @return Collection
29
     */
30
    public function championship($ctId)
31
    {
32
        //TODO Surely I could Refactor it to Eloquent - Should Debug that. $ctId <> $championshipId ???
33
        $competitor = self::where('championship_id', $ctId)->first();
34
        $championshipId = $competitor->championship_id;
35
        $championship = Championship::find($championshipId);
36
37
        return $championship;
38
    }
39
40
    /**
41
     * Not sure I use it, I could use $competitor->championship->category.
42
     *
43
     * @param $ctuId
44
     *
45
     * @return mixed
46
     */
47
    public function category($ctuId)
48
    {
49
        $championship = $this->championship($ctuId);
50
        $categoryId = $championship->category_id;
51
        $cat = Category::find($categoryId);
52
53
        return $cat;
54
    }
55
56
    /**
57
     * Get the tournament where Competitors is competing.
58
     *
59
     * @param $ctuId
60
     *
61
     * @return mixed
62
     */
63
    public function tournament($ctuId)
64
    {
65
        $tc = $this->championship($ctuId);
66
        $tourmanentId = $tc->tournament_id;
67
        $tour = Tournament::findOrNew($tourmanentId);
68
69
        return $tour;
70
    }
71
72
    /**
73
     * Get User from Competitor.
74
     *
75
     * @return mixed
76
     */
77
    public function user()
78
    {
79
        return $this->belongsTo(User::class);
80
    }
81
82
    public function fightersGroups()
83
    {
84
        return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps();
85
    }
86
87
    public function getName()
88
    {
89
        if ($this == null) return "BYE";
90
        if ($this->user == null) return "BYE";
91
        return $this->user->name;
92
    }
93
}
94