ActiveableModel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 8 1
A object() 0 4 1
1
<?php
2
3
namespace Alish\ActiveableModel\Models;
4
5
use Carbon\Carbon;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * @property Carbon created_at
10
 * @property bool is_active
11
 */
12
class ActiveableModel extends Model
13
{
14
    public $timestamps = false;
15
16
    protected $guarded = [
17
        'id'
18
    ];
19
20
    protected $casts = [
21
        'created_at' => 'datetime',
22
        'status' => 'bool'
23
    ];
24
25
    protected static function boot()
26
    {
27
        parent::boot();
28
29
        static::creating(function (ActiveableModel $status) {
30
            $status->created_at = $status->freshTimestamp();
31
        });
32
    }
33
34
    public function object()
35
    {
36
        return $this->morphTo();
37
    }
38
}
39