RelationTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 30.76%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 0
dl 0
loc 44
ccs 4
cts 13
cp 0.3076
rs 10

5 Methods

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