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

Competitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 4 1
A getNameAttribute() 0 4 1
A getFullName() 0 4 1
A defaultName() 0 7 3
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