Passed
Push — master ( de2a89...024236 )
by Julien
04:22
created

Competitor::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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 null|string
33
     */
34
    public function getNameAttribute()
35
    {
36
        return $this->defaultName() ?? $this->user->name;
37
    }
38
39
    /**
40
     * @return null|string
41
     */
42
    public function getFullName() //TODO Should remove get prefix
43
    {
44
        return $this->defaultName() ?? $this->user->firstname . " " . $this->user->lastname;
45
    }
46
47
    /**
48
     * @return null|string
49
     */
50
    private function defaultName()
51
    {
52
        if ($this == null || $this->user == null) {
53
            return "";
54
        }
55
        return null;
56
    }
57
58
}
59