Completed
Push — develop ( e210c1...b7d5d2 )
by Mohamed
07:16 queued 59s
created

RelationTrait   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 88.24%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 12
c 6
b 0
f 0
lcom 2
cbo 1
dl 0
loc 137
ccs 30
cts 34
cp 0.8824
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A assigned() 0 4 1
A updatedBy() 0 4 1
A closer() 0 4 1
A user() 0 4 1
A project() 0 4 1
A attachments() 0 9 1
A activities() 0 6 1
A generalActivities() 0 7 1
A commentActivities() 0 7 1
A tags() 0 4 1
A comments() 0 6 1
A messagesQueue() 0 4 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\Project\Issue;
13
14
use Illuminate\Database\Eloquent\Builder;
15
use Illuminate\Database\Eloquent\Relations;
16
use Tinyissue\Model;
17
18
/**
19
 * RelationTrait is trait class containing the relationship methods for the Project\Issue model.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 *
23
 * @method Relations\HasMany       hasMany($related, $foreignKey = null, $localKey = null)
24
 * @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
25
 * @method Relations\BelongsTo     belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
26
 */
27
trait RelationTrait
28
{
29
    /**
30
     * An issue has one user assigned to (inverse relationship of User::issues).
31
     *
32
     * @return Relations\BelongsTo
33
     */
34 11
    public function assigned()
35
    {
36 11
        return $this->belongsTo('Tinyissue\Model\User', 'assigned_to');
37
    }
38
39
    /**
40
     * An issue has one user updated by (inverse relationship of User::issuesUpdatedBy).
41
     *
42
     * @return Relations\BelongsTo
43
     */
44 4
    public function updatedBy()
45
    {
46 4
        return $this->belongsTo('Tinyissue\Model\User', 'updated_by');
47
    }
48
49
    /**
50
     * An issue has one user closed it (inverse relationship of User::issuesClosedBy).
51
     *
52
     * @return Relations\BelongsTo
53
     */
54
    public function closer()
55
    {
56
        return $this->belongsTo('Tinyissue\Model\User', 'closed_by');
57
    }
58
59
    /**
60
     * An issue has one user created it (inverse relationship of User::issuesCreatedBy).
61
     *
62
     * @return Relations\BelongsTo
63
     */
64 15
    public function user()
65
    {
66 15
        return $this->belongsTo('Tinyissue\Model\User', 'created_by');
67
    }
68
69
    /**
70
     * Issue belong to a project.
71
     *
72
     * @return Relations\BelongsTo
73
     */
74 1
    public function project()
75
    {
76 1
        return $this->belongsTo('Tinyissue\Model\Project');
77
    }
78
79
    /**
80
     * Issue can have many attachments.
81
     *
82
     * @return Relations\HasMany
83
     */
84 13
    public function attachments()
85
    {
86
        return $this
87 13
            ->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'issue_id')
88 13
            ->where(function (Builder $query) {
89 13
                $query->where('comment_id', '=', 0);
90 13
                $query->orWhere('comment_id', '=', null);
91 13
            });
92
    }
93
94
    /**
95
     * Issue have many users activities.
96
     *
97
     * @return Relations\HasMany
98
     */
99 17
    public function activities()
100
    {
101
        return $this
102 17
            ->hasMany('Tinyissue\Model\User\Activity', 'item_id')
103 17
            ->orderBy('created_at', 'ASC');
104
    }
105
106
    /**
107
     * Issue have many users activities (all except comments).
108
     *
109
     * @return mixed
110
     */
111 1
    public function generalActivities()
112
    {
113
        return $this
114 1
            ->hasMany('Tinyissue\Model\User\Activity', 'item_id')
115 1
            ->whereNotIn('type_id', [Model\Activity::TYPE_COMMENT])
116 1
            ->orderBy('created_at', 'ASC');
117
    }
118
119
    /**
120
     * Issue have many users activities (comments).
121
     *
122
     * @return mixed
123
     */
124 6
    public function commentActivities()
125
    {
126
        return $this
127 6
            ->hasMany('Tinyissue\Model\User\Activity', 'item_id')
128 6
            ->whereIn('type_id', [Model\Activity::TYPE_COMMENT])
129 6
            ->orderBy('created_at', 'ASC');
130
    }
131
132
    /**
133
     * Issue have many tags.
134
     *
135
     * @return Relations\BelongsToMany
136
     */
137 17
    public function tags()
138
    {
139 17
        return $this->belongsToMany('Tinyissue\Model\Tag', 'projects_issues_tags', 'issue_id', 'tag_id');
140
    }
141
142
    /**
143
     * Issue have many comments.
144
     *
145
     * @return Relations\HasMany
146
     */
147 3
    public function comments()
148
    {
149
        return $this
150 3
            ->hasMany('Tinyissue\Model\Project\Issue\Comment', 'issue_id')
151 3
            ->orderBy('created_at', 'ASC');
152
    }
153
154
    /**
155
     * Issue can have many messages queue.
156
     *
157
     * @return Relations\HasMany
158
     */
159
    public function messagesQueue()
160
    {
161
        return $this->morphMany('Tinyissue\Model\Message\Queue', 'model');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
162
    }
163
}
164