Passed
Pull Request — 2.x (#1049)
by
unknown
07:15
created

Role   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 83
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getUsersCountAttribute() 0 3 1
A getCreatedAtAttribute() 0 3 1
A users() 0 3 1
A scopeDraft() 0 3 1
A scopeOnlyTrashed() 0 3 1
A scopePublished() 0 3 1
1
<?php
2
3
namespace A17\Twill\Models;
4
5
use A17\Twill\Models\User;
6
use A17\Twill\Models\Behaviors\HasMedias;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Collection;
9
use Illuminate\Database\Eloquent\SoftDeletes;
10
use A17\Twill\Models\Behaviors\HasPermissions;
11
use A17\Twill\Models\Behaviors\IsTranslatable;
12
use Illuminate\Database\Eloquent\Model as BaseModel;
13
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
14
15
/**
16
 * Role model
17
 *
18
 * @property-read string $createdAt Date of creation
19
 * @property-read string $usersCount Formatted number of users in this role (ie. '123 users')
20
 * @method static Builder published() Get published roles
21
 * @method static Builder draft() Get draft roles
22
 * @method static Builder onlyTrashed() Get trashed roles
23
 */
24
class Role extends BaseModel
25
{
26
    use HasMedias, SoftDeletes, HasPermissions, IsTranslatable;
0 ignored issues
show
introduced by
The trait A17\Twill\Models\Behaviors\HasMedias requires some properties which are not provided by A17\Twill\Models\Role: $medias, $role, $pivot, $metadatas, $uuid, $height, $lqip_data, $crop_h, $locale, $video, $crop, $crop_w, $width
Loading history...
Bug introduced by
The trait A17\Twill\Models\Behaviors\HasPermissions requires the property $permissions which is not provided by A17\Twill\Models\Role.
Loading history...
Bug introduced by
The trait A17\Twill\Models\Behaviors\IsTranslatable requires the property $translatedAttributes which is not provided by A17\Twill\Models\Role.
Loading history...
27
28
    public $timestamps = true;
29
30
    protected $fillable = [
31
        'name',
32
        'published',
33
        'in_everyone_group',
34
    ];
35
36
    protected $dates = [
37
        'deleted_at',
38
    ];
39
40
    public $checkboxes = ['published'];
41
42
    protected $casts = [
43
        'in_everyone_group' => 'boolean',
44
    ];
45
46
    /**
47
     * Scope published roles.
48
     *
49
     * @param Builder $query
50
     * @return Builder
51
     */
52
    public function scopePublished($query)
53
    {
54
        return $query->wherePublished(true);
55
    }
56
57
    /**
58
     * Scope unpublished (draft) roles.
59
     *
60
     * @param Builder $query
61
     * @return Builder
62
     */
63
    public function scopeDraft($query)
64
    {
65
        return $query->wherePublished(false);
66
    }
67
68
    /**
69
     * Scope trashed roles.
70
     *
71
     * @param Builder $query
72
     * @return Builder
73
     */
74
    public function scopeOnlyTrashed($query)
75
    {
76
        return $query->whereNotNull('deleted_at');
77
    }
78
79
    /**
80
     * User model relationship
81
     *
82
     * @return BelongsToMany|Collection|User[]
83
     */
84
    public function users()
85
    {
86
        return $this->hasMany(User::class);
87
    }
88
89
    /**
90
     * Return the formatted created date
91
     *
92
     * @return string
93
     */
94
    public function getCreatedAtAttribute($value)
95
    {
96
        return \Carbon\Carbon::parse($value)->format('d M Y');
97
    }
98
99
    /**
100
     * Return the formatted number of users in this group
101
     *
102
     * @return string
103
     */
104
    public function getUsersCountAttribute($value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

104
    public function getUsersCountAttribute(/** @scrutinizer ignore-unused */ $value)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
    {
106
        return $this->users->count() . ' users';
107
    }
108
}
109