RelationTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 60%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 5
c 3
b 2
f 0
lcom 0
cbo 0
dl 57
loc 57
ccs 6
cts 10
cp 0.6
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
morphMany() 1 1 ?
hasOne() 1 1 ?
hasMany() 1 1 ?
belongsTo() 1 1 ?
A user() 4 4 1
A issue() 4 4 1
A attachments() 4 4 1
A activity() 4 4 1
A messagesQueue() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Comment;
13
14
use Illuminate\Database\Eloquent\Relations;
15
16
/**
17
 * RelationTrait is trait class containing the relationship methods for the Project\Issue\Comment model.
18
 *
19
 * @author Mohamed Alsharaf <[email protected]>
20
 *
21
 * @property static $this
22
 */
23 View Code Duplication
trait RelationTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
{
25
    /**
26
     * A comment has one user (inverse relationship of User::comments).
27
     *
28
     * @return Relations\BelongsTo
29
     */
30
    public function user()
31
    {
32
        return $this->belongsTo('\Tinyissue\Model\User', 'created_by');
33
    }
34
35
    /**
36
     * A comment has belongs to an issue.
37
     *
38
     * @return Relations\BelongsTo
39
     */
40 5
    public function issue()
41
    {
42 5
        return $this->belongsTo('\Tinyissue\Model\Project\Issue', 'issue_id');
43
    }
44
45
    /**
46
     * Comment can have many attachments.
47
     *
48
     * @return Relations\HasMany
49
     */
50 9
    public function attachments()
51
    {
52 9
        return $this->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'comment_id');
53
    }
54
55
    /**
56
     * Comment can have one activity.
57
     *
58
     * @return Relations\HasOne
59
     */
60 10
    public function activity()
61
    {
62 10
        return $this->hasOne('Tinyissue\Model\User\Activity', 'action_id');
63
    }
64
65
    /**
66
     * Comment can have many messages queue.
67
     *
68
     * @return Relations\HasMany
69
     */
70
    public function messagesQueue()
71
    {
72
        return $this->morphMany('Tinyissue\Model\Message\Queue', 'model');
73
    }
74
75
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
76
    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
77
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
78
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
79
}
80