Completed
Pull Request — master (#11)
by
unknown
01:41
created

User   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A role() 0 4 1
A permissions() 0 4 1
A registerMediaCollections() 0 7 1
A setPasswordAttribute() 0 4 1
A getAvatarAttribute() 0 4 1
1
<?php
2
3
namespace Microboard\Models;
4
5
use Illuminate\Contracts\Auth\MustVerifyEmail;
6
use Illuminate\Database\Eloquent\Collection;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Foundation\Auth\User as Authenticatable;
9
use Spatie\MediaLibrary\HasMedia;
10
use Spatie\MediaLibrary\InteractsWithMedia;
11
12
class User extends Authenticatable implements MustVerifyEmail, HasMedia
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: addMedia, addMediaConversion, clearMediaCollection, clearMediaCollectionExcept, copyMedia, getMedia, hasMedia, loadMedia, media, registerAllMediaConversions, registerMediaConversions, shouldDeletePreservingMedia
Loading history...
13
{
14
    use InteractsWithMedia;
15
16
    /**
17
     * User constructor.
18
     *
19
     * @param array $attributes
20
     */
21
    public function __construct(array $attributes = [])
22
    {
23
        $this->fillable = array_merge([
24
            'role_id', 'name', 'email', 'password'
25
        ], $this->fillable);
26
27
        parent::__construct($attributes);
28
    }
29
30
    /**
31
     * @return BelongsTo
32
     */
33
    public function role()
34
    {
35
        return $this->belongsTo(Role::class);
36
    }
37
38
    /**
39
     * Retrieve role's permissions
40
     *
41
     * @return Collection
42
     */
43
    public function permissions()
44
    {
45
        return $this->role->permissions;
46
    }
47
48
    /**
49
     * Register media library collections.
50
     */
51
    public function registerMediaCollections(): void
52
    {
53
        $this->addMediaCollection('avatar')
54
            ->singleFile()
55
            ->useFallbackPath($avatar = asset('/storage/user-placeholder.png'))
56
            ->useFallbackUrl($avatar);
57
    }
58
59
    /**
60
     * Hash the password whenever updating.
61
     *
62
     * @param $value
63
     */
64
    public function setPasswordAttribute($value)
65
    {
66
        $this->attributes['password'] = bcrypt($value);
67
    }
68
69
    /**
70
     * Get user's avatar or get the placeholder
71
     *
72
     * @return string
73
     */
74
    public function getAvatarAttribute()
75
    {
76
        return $this->getFirstMediaUrl('avatar');
77
    }
78
}
79