Completed
Push — develop-3.0 ( 360277...bd5ff0 )
by Mohamed
06:52
created

UserRelations   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 90
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A role() 0 4 1
A comments() 0 4 1
A issuesCreatedBy() 0 4 1
A issuesClosedBy() 0 4 1
A issuesUpdatedBy() 0 4 1
A attachments() 0 4 1
A projects() 0 6 1
A issues() 0 4 1
belongsTo() 0 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;
13
14
use Illuminate\Database\Eloquent\Relations;
15
16
/**
17
 * UserRelations is trait class containing the relationship methods for the User model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23
trait UserRelations
24
{
25
    /**
26
     * A user has one role (inverse relationship of Role::users).
27
     *
28
     * @return Role
29
     */
30
    public function role()
31
    {
32
        return $this->belongsTo(Role::class, 'role_id');
33
    }
34
35
    /**
36
     * User has many comments (One-many relationship of Comment::user).
37
     *
38
     * @return Project\Issue\Comment
39
     */
40
    public function comments()
41
    {
42
        return $this->hasMany(Project\Issue\Comment::class, 'created_by', 'id');
43
    }
44
45
    /**
46
     * Returns issues created by the user.
47
     *
48
     * @return Project\Issue
49
     */
50
    public function issuesCreatedBy()
51
    {
52
        return $this->hasMany(Project\Issue::class, 'created_by');
53
    }
54
55
    /**
56
     * Returns issues closed by the user.
57
     *
58
     * @return Project\Issue
59
     */
60
    public function issuesClosedBy()
61
    {
62
        return $this->hasMany(Project\Issue::class, 'closed_by');
63
    }
64
65
    /**
66
     * Returns issues updated by the user.
67
     *
68
     * @return Project\Issue
69
     */
70
    public function issuesUpdatedBy()
71
    {
72
        return $this->hasMany(Project\Issue::class, 'updated_by');
73
    }
74
75
    /**
76
     * User has many attachments (One-many relationship of Attachment::user).
77
     *
78
     * @return Project\Issue\Attachment
79
     */
80
    public function attachments()
81
    {
82
        return $this->hasMany(Project\Issue\Attachment::class, 'uploaded_by');
83
    }
84
85
    /**
86
     * Returns all projects the user can access.
87
     *
88
     * @return Project
89
     */
90
    public function projects()
91
    {
92
        return $this
93
            ->belongsToMany(Project::class, 'projects_users')
94
            ->orderBy('name');
95
    }
96
97
    /**
98
     * User has many issues assigned to (One-many relationship of Issue::assigned).
99
     *
100
     * @return Project\Issue
101
     */
102
    public function issues()
103
    {
104
        return $this->hasMany(Project\Issue::class, 'assigned_to');
105
    }
106
107
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
108
109
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
110
111
    abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null);
112
}
113