Test Failed
Push — master ( b6687a...d5e75a )
by Julien
06:32
created

Competitor::defaultName()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Xoco70\LaravelTournaments\Models;
4
5
use Illuminate\Database\Eloquent\SoftDeletes;
6
use Illuminate\Foundation\Auth\User;
7
8
class Competitor extends Fighter
9
{
10
    use SoftDeletes;
11
    protected $DATES = ['created_at', 'updated_at', 'deleted_at'];
12
13
    protected $table = 'competitor';
14
    public $timestamps = true;
15
    protected $fillable = [
16
        'tournament_category_id',
17
        'user_id',
18
        'confirmed',
19
    ];
20
21
    /**
22
     * Get User from Competitor.
23
     *
24
     * @return mixed
25
     */
26
    public function user()
27
    {
28
        return $this->belongsTo(User::class);
29
    }
30
31
    /**
32
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
33
     */
34
    public function fightersGroups()
35
    {
36
        return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps();
37
    }
38
39
    /**
40
     * @return null|string
41
     */
42
    public function getNameAttribute()
43
    {
44
        return $this->defaultName() ?? $this->user->name;
45
    }
46
47
    /**
48
     * @return null|string
49
     */
50
    public function getFullName()
51
    {
52
        return $this->defaultName() ?? $this->user->firstname . " " . $this->user->lastname;
53
    }
54
55
    /**
56
     * @return null|string
57
     */
58
    private function defaultName()
59
    {
60
        if ($this == null || $this->user == null) {
61
            return "";
62
        }
63
        return null;
64
    }
65
66
}
67