Passed
Push — master ( 1d6548...c98942 )
by Julien
29:57
created

Competitor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 4 1
A fightersGroups() 0 4 1
A getName() 0 4 1
A getFullName() 0 4 1
A defaultName() 0 5 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
9
class Competitor extends Fighter
10
{
11
    use SoftDeletes;
12
    protected $DATES = ['created_at', 'updated_at', 'deleted_at'];
13
14
    protected $table = 'competitor';
15
    public $timestamps = true;
16
    protected $fillable = [
17
        'tournament_category_id',
18
        'user_id',
19
        'confirmed',
20
    ];
21
22
    /**
23
     * Get User from Competitor.
24
     *
25
     * @return mixed
26
     */
27
    public function user()
28
    {
29
        return $this->belongsTo(User::class);
30
    }
31
32
    /**
33
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
34
     */
35
    public function fightersGroups()
36
    {
37
        return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps();
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43
    public function getName()
44
    {
45
        return $this->defaultName() ?? $this->user->name;
46
    }
47
48
    /**
49
     * @return null|string
50
     */
51
    public function getFullName()
52
    {
53
        return $this->defaultName() ?? $this->user->firstname . " " . $this->user->lastname;
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59
    private function defaultName()
60
    {
61
        if ($this == null || $this->user == null) return "BYE";
62
        return null;
63
    }
64
65
}
66