Completed
Push — master ( 50f309...1f3d4e )
by Mohamed
06:23
created

RelationTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
c 4
b 0
f 0
lcom 0
cbo 0
dl 0
loc 42
ccs 4
cts 8
cp 0.5
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A parent() 0 4 1
A tags() 0 4 1
A issues() 0 4 1
A projects() 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\Tag;
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
 * @method Relations\HasMany       hasMany($related, $foreignKey = null, $localKey = null)
22
 * @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
23
 * @method Relations\BelongsTo     belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
24
 */
25
trait RelationTrait
26
{
27
    /**
28
     * Returns the parent/group for the tag.
29
     *
30
     * @return Relations\BelongsTo
31
     */
32 25
    public function parent()
33
    {
34 25
        return $this->belongsTo('Tinyissue\Model\Tag', 'parent_id');
35
    }
36
37
    /**
38
     * Parent tag/group have many tags.
39
     *
40
     * @return Relations\HasMany
41
     */
42 5
    public function tags()
43
    {
44 5
        return $this->hasMany('Tinyissue\Model\Tag', 'parent_id');
45
    }
46
47
    /**
48
     * Returns issues for the Tag. Tag can belong to many issues & issue can have many tags.
49
     *
50
     * @return Relations\BelongsToMany
51
     */
52
    public function issues()
53
    {
54
        return $this->belongsToMany('Tinyissue\Model\Project\Issue', 'projects_issues_tags', 'issue_id', 'tag_id');
55
    }
56
57
    /**
58
     * Returns projects for the Tag. Tag can belong to many projects & project can have many tags.
59
     *
60
     * @return Relations\BelongsToMany
61
     */
62
    public function projects()
63
    {
64
        return $this->belongsToMany('Tinyissue\Model\Project', 'projects_kanban_tags', 'project_id', 'tag_id');
65
    }
66
}
67