Travel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 17.78 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 8
loc 45
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 4 1
A author() 0 4 1
A attachments() 0 4 1
A setAttribute() 8 8 3

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
namespace SET;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Travel extends Model
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $table = 'travels';
13
    /**
14
     * @var bool
15
     */
16
    public $timestamps = true;
17
    /**
18
     * @var array
19
     */
20
    protected $fillable = ['location', 'brief_date', 'debrief_date', 'leave_date', 'return_date', 'comment', 'is_ready', 'author_id', 'user_id'];
21
22
    public function user()
23
    {
24
        return $this->belongsTo('SET\User');
25
    }
26
27
    public function author()
28
    {
29
        return $this->belongsTo('SET\User', 'author_id');
30
    }
31
32
    public function attachments()
33
    {
34
        return $this->morphMany('SET\Attachment', 'imageable');
35
    }
36
37
    /**
38
     * @param string $key
39
     * @param mixed  $value
40
     *
41
     * @return $this
42
     */
43 View Code Duplication
    public function setAttribute($key, $value)
44
    {
45
        if (is_scalar($value) && $value === '') {
46
            $value = null;
47
        }
48
49
        return parent::setAttribute($key, $value);
50
    }
51
}
52