Completed
Push — master ( a1f3ed...74c577 )
by Kirill
02:49
created

Karma   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 19.12 %
Metric Value
wmc 2
dl 13
loc 68
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ toArray() 7 7 1
A boot() 0 13 2
A user() 0 4 1
A target() 0 4 1
A getCreatedAtAttribute() 13 13 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
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 09.10.2015 20:15
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Domains;
12
13
use Carbon\Carbon;
14
use Illuminate\Contracts\Support\Arrayable;
15
16
/**
17
 * Class Karma
18
 *
19
 * @property-read int $id
20
 * @property string $room_id
21
 * @property string $message_id
22
 * @property int $user_id
23
 * @property int $user_target_id
24
 * @property string $status
25
 *
26
 * === Relations ===
27
 *
28
 * @property-read User $user
29
 * @property-read User $target
30
 *
31
 * === Accessors ===
32
 *
33
 * @property string $created_at
34
 *
35
 */
36
class Karma extends \Eloquent
37
{
38
    /**
39
     * @var string
40
     */
41
    protected $table = 'karma';
42
43
    /**
44
     * @var array
45
     */
46
    public $timestamps = false;
47
48
    /**
49
     * @var array
50
     */
51
    protected $guarded = ['id'];
52
53
    /**
54
     * Boot
55
     */
56
    public static function boot()
57
    {
58
        parent::boot();
59
60
        static::creating(function (Karma $karma) {
61
            if (!$karma->created_at) {
62
                $karma->created_at = $karma->freshTimestamp();
63
            }
64
65
            \Event::fire('karma.add', ['karma' => $karma]);
66
        });
67
68
    }
69
70
    /**
71
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
72
     */
73
    public function user()
74
    {
75
        return $this->belongsTo(User::class, 'user_id', 'id');
76
    }
77
78
    /**
79
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
80
     */
81
    public function target()
82
    {
83
        return $this->belongsTo(User::class, 'user_target_id', 'id');
84
    }
85
86
    /**
87
     * @param $time
88
     * @return Carbon
89
     */
90 View Code Duplication
    public function getCreatedAtAttribute($time)
0 ignored issues
show
Duplication introduced by
This method 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...
91
    {
92
        return new class($time) extends Carbon implements Arrayable
93
        {
94
            public function toArray()
95
            {
96
                return [
97
                    'date'     => $this->toIso8601String(),
98
                    'timezone' => $this->timezone,
99
                ];
100
            }
101
        };
102
    }
103
}
104