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