Passed
Push — 5.0.0 ( 196a2e...76aff9 )
by Fèvre
05:12
created

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