User::getFileName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace FaithGen\SDK\Models;
4
5
use FaithGen\SDK\Traits\Relationships\Has\ManyMinistryUsers;
6
use FaithGen\SDK\Traits\Relationships\Morphs\CreatableTrait;
7
use FaithGen\SDK\Traits\Relationships\Morphs\ImageableTrait;
8
use FaithGen\SDK\Traits\StorageTrait;
9
use Illuminate\Foundation\Auth\User as Authenticatable;
10
use Illuminate\Notifications\Notifiable;
11
12
class User extends Authenticatable
13
{
14
    use ManyMinistryUsers;
15
    use CreatableTrait;
16
    use Notifiable;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Notifications\Notifiable requires the property $email which is not provided by FaithGen\SDK\Models\User.
Loading history...
17
    use ImageableTrait;
18
    use StorageTrait;
19
20
    protected $table = 'fg_users';
21
    protected $guarded = ['id'];
22
    public $incrementing = false;
23
    protected $hidden = [
24
        'password',
25
        'created_at',
26
        'updated_at',
27
        'remember_token',
28
    ];
29
30
    //****************************************************************************//
31
    //***************************** MODEL ATTRIBUTES *****************************//
32
    //****************************************************************************//
33
34
    public function getNameAttribute($val)
35
    {
36
        return ucwords($val);
37
    }
38
39
    //****************************************************************************//
40
    //***************************** MODEL RELATIONSHIPS *****************************//
41
    //****************************************************************************//
42
43
    /**
44
     * Links comments to this user.
45
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
46
     */
47
    public function comments()
48
    {
49
        return $this->hasMany(Comment::class);
50
    }
51
52
    public function getMinistriesAttribute()
53
    {
54
        return Ministry::whereHas('ministryUsers', function ($minUser) {
55
            return $minUser->where('user_id', $this->id);
56
        });
57
    }
58
59
    public function getActiveAttribute(): bool
60
    {
61
        if ($user = $this->ministryUsers()->where('ministry_id', auth()->user()->id)->first()) {
62
            return (bool) $user->active;
63
        }
64
65
        return false;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function filesDir()
72
    {
73
        return 'users';
74
    }
75
76
    public function getFileName()
77
    {
78
        return $this->image->name;
0 ignored issues
show
Bug introduced by
The property image does not seem to exist on FaithGen\SDK\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
79
    }
80
81
    public function getImageDimensions()
82
    {
83
        return [0, 50];
84
    }
85
}
86