Completed
Branch develop-3.0 (4fe777)
by Mohamed
11:06
created

RoleRelations   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A users() 7 7 1
A projectUsers() 4 4 1
A permissions() 10 10 1
hasMany() 1 1 ?
belongsToMany() 1 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
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model;
13
14
use Illuminate\Database\Eloquent\Relations;
15
16
/**
17
 * RelationTrait is trait class containing the relationship methods for the Role model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23 View Code Duplication
trait RoleRelations
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...
24
{
25
    /**
26
     * Role has many users (One-many relationship of User::role).
27
     *
28
     * @return Relations\HasMany
29
     */
30
    public function users()
31
    {
32
        return $this
33
            ->hasMany('Tinyissue\Model\User', 'role_id', 'id')
34
            ->where('deleted', '=', User::NOT_DELETED_USERS)
35
            ->orderBy('firstname', 'asc');
36
    }
37
38
    /**
39
     * Role has many users in a project_users.
40
     *
41
     * @return Relations\HasMany
42
     */
43
    public function projectUsers()
44
    {
45
        return $this->hasMany('Tinyissue\Model\Project\User');
46
    }
47
48
    /**
49
     * Role has many role permission.
50
     *
51
     * @return Relations\BelongsToMany
52
     */
53
    public function permissions()
54
    {
55
        return $this->belongsToMany(
56
            '\Tinyissue\Model\Permission',
57
            'roles_permissions',
58
            'role_id',
59
            'permission_id',
60
            'role_id'
61
        );
62
    }
63
64
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
65
    abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null);
66
}
67