Completed
Push — develop ( a46361...3940dc )
by Mohamed
08:07
created

RelationTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 8
c 6
b 1
f 0
lcom 2
cbo 0
dl 0
loc 86
ccs 16
cts 18
cp 0.8889
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A issues() 0 4 1
A issuesByUser() 0 4 1
A users() 0 4 1
A user() 0 4 1
A projectUsers() 0 4 1
A activities() 0 4 1
A notes() 0 4 1
A kanbanTags() 0 6 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;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model\Project;
16
use Tinyissue\Model\Tag;
17
18
/**
19
 * RelationTrait is trait class containing the relationship methods for the Project 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
 */
26
trait RelationTrait
27
{
28
    /**
29
     * Returns all issues related to project.
30
     *
31
     * @return Relations\HasMany
32
     */
33 11
    public function issues()
34
    {
35 11
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'project_id');
36
    }
37
38
    /**
39
     * Returns issues in the project with user details eager loaded.
40
     *
41
     * @return Relations\HasMany
42
     */
43
    public function issuesByUser()
44
    {
45
        return $this->hasMany('Tinyissue\Model\Project\Issue', 'project_id')->with('user')->get();
46
    }
47
48
    /**
49
     * Returns all users assigned in the current project.
50
     *
51
     * @return Relations\BelongsToMany
52
     */
53 37
    public function users()
54
    {
55 37
        return $this->belongsToMany('\Tinyissue\Model\User', 'projects_users', 'project_id', 'user_id');
56
    }
57
58
    /**
59
     * Return a user that is member of a project.
60
     *
61
     * @param int $userId
62
     *
63
     * @return Relations\BelongsToMany
64
     */
65 8
    public function user($userId)
66
    {
67 8
        return $this->users()->where('user_id', '=', (int) $userId);
68
    }
69
70
    /**
71
     * Project has many project users.
72
     *
73
     * @return Relations\HasMany
74
     */
75 25
    public function projectUsers()
76
    {
77 25
        return $this->hasMany('Tinyissue\Model\Project\User', 'project_id');
78
    }
79
80
    /**
81
     * Returns project activities.
82
     *
83
     * @return Relations\HasMany
84
     */
85 12
    public function activities()
86
    {
87 12
        return $this->hasMany('Tinyissue\Model\User\Activity', 'parent_id');
88
    }
89
90
    /**
91
     * Returns notes in the project.
92
     *
93
     * @return Relations\HasMany
94
     */
95 21
    public function notes()
96
    {
97 21
        return $this->hasMany('Tinyissue\Model\Project\Note', 'project_id');
98
    }
99
100
    /**
101
     * Project have many kanban tags.
102
     *
103
     * @return Relations\BelongsToMany
104
     */
105 8
    public function kanbanTags()
106
    {
107 8
        return $this->belongsToMany('Tinyissue\Model\Tag', 'projects_kanban_tags', 'project_id', 'tag_id')
108 8
            ->whereNotIn('name', [Tag::STATUS_OPEN, Tag::STATUS_CLOSED])
109 8
            ->orderBy('position');
110
    }
111
}
112