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

TagRelations   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A parent() 0 4 1
A tags() 0 4 1
A userAccessibleTags() 0 4 1
A issues() 0 4 1
A projects() 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
 * RelationTrait is trait class containing the relationship methods for the Tag model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23
trait TagRelations
24
{
25
    /**
26
     * Returns the parent/group for the tag.
27
     *
28
     * @return Tag
29
     */
30
    public function parent()
31
    {
32
        return $this->belongsTo(Tag::class, 'parent_id');
33
    }
34
35
    /**
36
     * Parent tag/group have many tags.
37
     *
38
     * @return Tag
39
     */
40
    public function tags()
41
    {
42
        return $this->hasMany(Tag::class, 'parent_id');
43
    }
44
45
    /**
46
     * Relation to tags that are accessible to current logged user.
47
     *
48
     * @return Tag
49
     */
50
    public function userAccessibleTags()
51
    {
52
        return $this->tags()->accessibleToLoggedUser();
53
    }
54
55
    /**
56
     * Returns issues for the Tag. Tag can belong to many issues & issue can have many tags.
57
     *
58
     * @return Project\Issue
59
     */
60
    public function issues()
61
    {
62
        return $this->belongsToMany(Project\Issue::class, 'projects_issues_tags', 'issue_id', 'tag_id');
63
    }
64
65
    /**
66
     * Returns projects for the Tag. Tag can belong to many projects & project can have many tags.
67
     *
68
     * @return Project
69
     */
70
    public function projects()
71
    {
72
        return $this->belongsToMany(Project::class, 'projects_kanban_tags', 'project_id', 'tag_id');
73
    }
74
75
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
76
77
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
78
79
    abstract public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null);
80
}
81