Passed
Push — 5.0.0 ( 78f010...4a0fb0 )
by Fèvre
05:30
created

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