Completed
Push — develop ( 1c3d8e...dc7d05 )
by Mohamed
07:44
created

RelationTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 60%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 4 4 1
A issue() 4 4 1
A attachments() 4 4 1
A messagesQueue() 4 4 1
A activity() 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
 * @method Relations\HasMany   hasMany($related, $foreignKey = null, $localKey = null)
22
 * @method Relations\BelongsTo belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
23
 * @method Relations\HasOne    hasOne($related, $foreignKey = null, $localKey = null)
24
 */
25 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...
26
{
27
    /**
28
     * A comment has one user (inverse relationship of User::comments).
29
     *
30
     * @return Relations\BelongsTo
31
     */
32
    public function user()
33
    {
34
        return $this->belongsTo('\Tinyissue\Model\User', 'created_by');
35
    }
36
37
    /**
38
     * A comment has belongs to an issue
39
     *
40
     * @return Relations\BelongsTo
41
     */
42 3
    public function issue()
43
    {
44 3
        return $this->belongsTo('\Tinyissue\Model\Project\Issue', 'issue_id');
45
    }
46
47
    /**
48
     * Comment can have many attachments.
49
     *
50
     * @return Relations\HasMany
51
     */
52 9
    public function attachments()
53
    {
54 9
        return $this->hasMany('Tinyissue\Model\Project\Issue\Attachment', 'comment_id');
55
    }
56
57
    /**
58
     * Comment can have one activity.
59
     *
60
     * @return Relations\HasOne
61
     */
62 9
    public function activity()
63
    {
64 9
        return $this->hasOne('Tinyissue\Model\User\Activity', 'action_id');
65
    }
66
67
    /**
68
     * Comment can have many messages queue.
69
     *
70
     * @return Relations\HasMany
71
     */
72
    public function messagesQueue()
73
    {
74
        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...
75
    }
76
}
77