anonymous//app/Domains/Karma.php$0   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 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
 * @deprecated
19
 *
20
 * @property-read int $id
21
 * @property string $room_id
22
 * @property string $message_id
23
 * @property int $user_id
24
 * @property int $user_target_id
25
 * @property string $status
26
 *
27
 * === Relations ===
28
 *
29
 * @property-read User $user
30
 * @property-read User $target
31
 *
32
 * === Accessors ===
33
 *
34
 * @property string $created_at
35
 *
36
 */
37
class Karma extends \Eloquent
38
{
39
    /**
40
     * @var string
41
     */
42
    protected $table = 'karma';
43
44
    /**
45
     * @var array
46
     */
47
    public $timestamps = false;
48
49
    /**
50
     * @var array
51
     */
52
    protected $guarded = ['id'];
53
54
    /**
55
     * Boot
56
     */
57
    public static function boot()
58
    {
59
        parent::boot();
60
61
        static::creating(function (Karma $karma) {
62
            if (!$karma->created_at) {
63
                $karma->created_at = $karma->freshTimestamp();
64
            }
65
66
            \Event::fire('karma.add', ['karma' => $karma]);
67
        });
68
69
    }
70
71
    /**
72
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
73
     */
74
    public function user()
75
    {
76
        return $this->belongsTo(User::class, 'user_id', 'id');
77
    }
78
79
    /**
80
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
81
     */
82
    public function target()
83
    {
84
        return $this->belongsTo(User::class, 'user_target_id', 'id');
85
    }
86
87
    /**
88
     * @param $time
89
     * @return Carbon
90
     */
91 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...
92
    {
93
        return new class($time) extends Carbon implements Arrayable
94
        {
95
            public function toArray()
96
            {
97
                return [
98
                    'date'     => $this->toIso8601String(),
99
                    'timezone' => $this->timezone,
100
                ];
101
            }
102
        };
103
    }
104
}
105