RelationTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 0
dl 48
loc 48
ccs 7
cts 9
cp 0.7778
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createdBy() 4 4 1
A project() 4 4 1
A activity() 6 6 1
A messagesQueue() 4 4 1
morphMany() 1 1 ?
hasOne() 1 1 ?
belongsTo() 1 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\Note;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model;
16
17
/**
18
 * RelationTrait is trait class containing the relationship methods for the Project\Note model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @property static $this
23
 */
24 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...
25
{
26
    /**
27
     * Note created by a user.
28
     *
29
     * @return Relations\BelongsTo
30
     */
31 6
    public function createdBy()
32
    {
33 6
        return $this->belongsTo('Tinyissue\Model\User', 'created_by');
34
    }
35
36
    /**
37
     * Note belong to a project.
38
     *
39
     * @return Relations\BelongsTo
40
     */
41 1
    public function project()
42
    {
43 1
        return $this->belongsTo('Tinyissue\Model\Project', 'project_id');
44
    }
45
46
    /**
47
     * Note has a user activity record.
48
     *
49
     * @return Relations\HasOne
50
     */
51 7
    public function activity()
52
    {
53
        return $this
54 7
            ->hasOne('Tinyissue\Model\User\Activity', 'action_id')
55 7
            ->where('type_id', '=', Model\Activity::TYPE_NOTE);
56
    }
57
58
    /**
59
     * Note can have many messages queue.
60
     *
61
     * @return Relations\HasMany
62
     */
63
    public function messagesQueue()
64
    {
65
        return $this->morphMany('Tinyissue\Model\Message\Queue', 'model');
66
    }
67
68
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
69
    abstract public function hasOne($related, $foreignKey = null, $localKey = null);
70
    abstract public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null);
71
}
72