Completed
Push — issue-37 ( e24320...44d7c4 )
by Fèvre
03:48
created

Ruby   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 59
loc 59
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 9 9 1
A user() 4 4 1
A obtainable() 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
namespace Xetaravel\Models;
3
4
use Illuminate\Support\Facades\Auth;
5
6 View Code Duplication
class Ruby extends Model
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...
7
{
8
    /**
9
     * The attributes that are mass assignable.
10
     *
11
     * @var array
12
     */
13
    protected $fillable = [
14
        'user_id',
15
        'obtainable_id',
16
        'obtainable_type',
17
        'event_type',
18
        'data'
19
    ];
20
21
    /**
22
     * The attributes that should be cast to native types.
23
     *
24
     * @var array
25
     */
26
    protected $casts = [
27
        'data' => 'array'
28
    ];
29
30
    /**
31
     * The "booting" method of the model.
32
     *
33
     * @return void
34
     */
35
    protected static function boot()
36
    {
37
        parent::boot();
38
39
        // Set the user id to the new log before saving it.
40
        static::creating(function ($model) {
41
            $model->user_id = Auth::id();
42
        });
43
    }
44
45
    /**
46
     * Get the user that owns the log.
47
     *
48
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
49
     */
50
    public function user()
51
    {
52
        return $this->belongsTo(User::class);
53
    }
54
55
    /**
56
     * Get the obtainable relation.
57
     *
58
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
59
     */
60
    public function obtainable()
61
    {
62
        return $this->morphTo();
63
    }
64
}
65