Passed
Push — 5.0.0 ( 631120...f07a46 )
by Fèvre
16:06
created

User::settings()   A

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
declare(strict_types=1);
4
5
namespace Xetaravel\Models;
6
7
use Illuminate\Auth\Authenticatable;
8
use Illuminate\Auth\MustVerifyEmail;
9
use Illuminate\Auth\Passwords\CanResetPassword;
10
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
11
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
12
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
13
use Illuminate\Contracts\Auth\MustVerifyEmail as MustVerifyEmailContract;
14
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
15
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
16
use Illuminate\Database\Eloquent\Relations\HasMany;
17
use Illuminate\Database\Eloquent\Relations\HasOne;
18
use Illuminate\Database\Eloquent\Relations\MorphMany;
19
use Illuminate\Foundation\Auth\Access\Authorizable;
20
use Illuminate\Notifications\DatabaseNotification;
21
use Illuminate\Notifications\Notifiable;
22
use Spatie\MediaLibrary\HasMedia;
23
use Spatie\MediaLibrary\InteractsWithMedia;
24
use Spatie\MediaLibrary\MediaCollections\Models\Media;
25
use Spatie\Permission\Traits\HasRoles;
0 ignored issues
show
Bug introduced by
The type Spatie\Permission\Traits\HasRoles was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Xetaravel\Models\Presenters\UserPresenter;
27
use Xetaravel\Notifications\Auth\ResetPassword;
28
use Xetaravel\Notifications\Auth\VerifyEmail;
29
use Xetaravel\Observers\UserObserver;
30
31
#[ObservedBy([UserObserver::class])]
32
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract, HasMedia, MustVerifyEmailContract
33
{
34
    use Authenticatable;
35
    use Authorizable;
36
    use CanResetPassword;
37
    use HasRoles;
38
    use InteractsWithMedia;
39
    use MustVerifyEmail;
40
    use Notifiable;
41
    use UserPresenter;
42
43
    /**
44
     * The attributes that are mass assignable.
45
     *
46
     * @var array
47
     */
48
    protected $fillable = [
49
        'username',
50
        'email',
51
        'password',
52
        'slug',
53
        'github_id',
54
        'register_ip',
55
        'last_login_ip',
56
        'last_login_date',
57
        'email_verified_at',
58
    ];
59
60
    /**
61
     * The attributes that should be hidden for arrays.
62
     *
63
     * @var array
64
     */
65
    protected $hidden = [
66
        'password',
67
        'remember_token',
68
    ];
69
70
    /**
71
     * The accessors to append to the model's array form.
72
     *
73
     * @var array
74
     */
75
    protected $appends = [
76
        'profile_background',
77
        'profile_url',
78
79
        // Media Model
80
        'avatar_small',
81
        'avatar_medium',
82
        'avatar_big',
83
        'avatar_primary_color',
84
85
        // Account Model
86
        'first_name',
87
        'last_name',
88
        'full_name',
89
        'biography',
90
        'signature',
91
        'facebook',
92
        'twitter',
93
94
        // Session Model
95
        'online',
96
97
        // Role Model
98
        'level',
99
    ];
100
101
    /**
102
     * The attributes that should be cast.
103
     */
104
    protected function casts(): array
105
    {
106
        return [
107
            'email_verified_at' => 'datetime',
108
            'password' => 'hashed',
109
            'last_login_date' => 'datetime',
110
        ];
111
    }
112
113
    /**
114
     * Register the related to the Model.
115
     */
116
    public function registerMediaConversions(?Media $media = null): void
117
    {
118
        $this->addMediaConversion('thumbnail.small')
119
            ->width(100)
120
            ->height(100)
121
            ->keepOriginalImageFormat();
122
123
        $this->addMediaConversion('thumbnail.medium')
124
            ->width(200)
125
            ->height(200)
126
            ->keepOriginalImageFormat();
127
128
        $this->addMediaConversion('thumbnail.big')
129
            ->width(300)
130
            ->height(300)
131
            ->keepOriginalImageFormat();
132
133
        $this->addMediaConversion('original')
134
            ->keepOriginalImageFormat();
135
    }
136
137
    /**
138
     * Get the comments for the user.
139
     *
140
     * @return HasMany
141
     */
142
    public function comments(): HasMany
143
    {
144
        return $this->hasMany(Comment::class);
145
    }
146
147
    /**
148
     * Get the articles for the user.
149
     *
150
     * @return HasMany
151
     */
152
    public function articles(): HasMany
153
    {
154
        return $this->hasMany(Article::class);
155
    }
156
157
    /**
158
     * Get the account for the user.
159
     *
160
     * @return HasOne
161
     */
162
    public function account(): HasOne
163
    {
164
        return $this->hasOne(Account::class);
165
    }
166
167
    /**
168
     * Get the badges for the user.
169
     *
170
     * @return BelongsToMany
171
     */
172
    public function badges(): BelongsToMany
173
    {
174
        return $this->belongsToMany(Badge::class)->withTimestamps();
175
    }
176
177
    /**
178
     * Get the notifications for the user.
179
     *
180
     * @return MorphMany
181
     */
182
    public function notifications(): MorphMany
183
    {
184
        return $this->morphMany(DatabaseNotification::class, 'notifiable')
185
            ->orderBy('read_at', 'asc')
186
            ->orderBy('created_at', 'desc');
187
    }
188
189
    /**
190
     * Get the discuss posts for the user.
191
     *
192
     * @return HasMany
193
     */
194
    public function discussPosts(): HasMany
195
    {
196
        return $this->hasMany(DiscussPost::class);
197
    }
198
199
    /**
200
     * Get the discuss conversations for the user.
201
     *
202
     * @return HasMany
203
     */
204
    public function discussConversations(): HasMany
205
    {
206
        return $this->hasMany(DiscussConversation::class);
207
    }
208
209
    /**
210
     * Get the discuss users for the user.
211
     *
212
     * @return HasMany
213
     */
214
    public function discussUsers(): HasMany
215
    {
216
        return $this->hasMany(DiscussUser::class);
217
    }
218
219
    /**
220
     * Get the discuss logs for the user.
221
     *
222
     * @return HasMany
223
     */
224
    public function discussLogs(): HasMany
225
    {
226
        return $this->hasMany(DiscussLog::class);
227
    }
228
229
    /**
230
     * Get the rubies for the user.
231
     *
232
     * @return HasMany
233
     */
234
    public function rubies(): HasMany
235
    {
236
        return $this->hasMany(Ruby::class);
237
    }
238
239
    /**
240
     * Get the experiences for the user.
241
     *
242
     * @return HasMany
243
     */
244
    public function experiences(): HasMany
245
    {
246
        return $this->hasMany(Experience::class);
247
    }
248
249
    /**
250
     * Send the password reset notification.
251
     *
252
     * @param string $token
253
     *
254
     * @return void
255
     */
256
    public function sendPasswordResetNotification($token): void
257
    {
258
        $this->notify(new ResetPassword($token));
259
    }
260
261
    /**
262
     * Send the email verification notification.
263
     *
264
     * @return void
265
     */
266
    public function sendEmailVerificationNotification(): void
267
    {
268
        $this->notify(new VerifyEmail());
269
    }
270
271
    /**
272
     * Get the setting for the user.
273
     *
274
     * @return MorphMany
275
     */
276
    public function settings(): MorphMany
277
    {
278
        return $this->morphMany(Setting::class, 'model');
279
    }
280
}
281