BaseRole   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 84.62 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 44
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A permissions() 9 9 1
A assignPermission() 6 6 1
A hasPermission() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MultiTenantLaravel\App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7 View Code Duplication
abstract class BaseRole extends Model
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    public $table = 'multi_tenant_roles';
10
11
    /**
12
     * The attributes that are mass assignable.
13
     *
14
     * @var array
15
     */
16
    protected $fillable = [
17
        'name', 'label', 'description',
18
    ];
19
20
    /**
21
     *  The permissions relationship
22
     */
23
    public function permissions()
24
    {
25
        return $this->belongsToMany(
26
            config('multi-tenant.permission_class'),
27
            'multi_tenant_permission_multi_tenant_role',
28
            'multi_tenant_role_id',
29
            'multi_tenant_permission_id'
30
        );
31
    }
32
33
    /**
34
     * Assign the given permission to the role
35
     *
36
     * @param BasePermission $permission
37
     *
38
     * @return void
39
     */
40
    public function assignPermission(BasePermission $permission)
41
    {
42
        $this->permissions()->syncWithoutDetaching([$permission->id]);
43
44
        return $this;
45
    }
46
47
    /**
48
     * Check if the role has the given permission
49
     *
50
     * @param BasePermission $permission
51
     *
52
     * @return boolean
53
     */
54
    public function hasPermission(BasePermission $permission)
55
    {
56
        return $this->permissions()->where('multi_tenant_permission_id', $permission->id)->exists();
57
    }
58
}
59