Passed
Push — master ( d616eb...59b1f2 )
by Julien
33:28
created

Competitor::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
27
     */
28
    public function championship()
29
    {
30
        return $this->belongsTo(Championship::class);
31
    }
32
33
    /**
34
     * Get User from Competitor.
35
     *
36
     * @return mixed
37
     */
38
    public function user()
39
    {
40
        return $this->belongsTo(User::class);
41
    }
42
43
    /**
44
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
45
     */
46
    public function fightersGroups()
47
    {
48
        return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps();
49
    }
50
51
    /**
52
     * @return null|string
53
     */
54
    public function getName()
55
    {
56
        return $this->defaultName() ?? $this->user->name;
57
    }
58
59
    /**
60
     * @return null|string
61
     */
62
    public function getFullName()
63
    {
64
        return $this->defaultName() ?? $this->user->firstname . " " . $this->user->lastname;
65
    }
66
67
    /**
68
     * @return null|string
69
     */
70
    private function defaultName()
71
    {
72
        if ($this == null) return "BYE";
73
        if ($this->user == null) return "BYE";
74
        return null;
75
    }
76
77
}
78