EntityLock   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 51
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A entity() 0 4 1
A user() 0 8 2
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Database\Eloquent\EntityLock;
12
13
use Longman\Platfourm\Database\Eloquent\Model;
14
use Longman\Platfourm\User\Models\Eloquent\User;
15
16
class EntityLock extends Model
17
{
18
19
    public $timestamps = false;
20
21
    /**
22
     * The database table used by the model.
23
     *
24
     * @var string
25
     */
26
    protected $table = 'entity_locks';
27
28
    /**
29
     * The attributes that are mass assignable.
30
     *
31
     * @var array
32
     */
33
    protected $fillable = [
34
        'entity_type', 'entity_id', 'locked_at', 'locked_by'
35
    ];
36
37
    protected $dates = ['locked_at'];
38
39
40
    public static function boot()
41
    {
42
        static::creating(function ($model) {
43
            $model->locked_at = $model->freshTimestamp();
44
        });
45
    }
46
47
    /**
48
     * Polymorphic relationship. Name of the relationship should be
49
     * the same as the prefix for the *_id/*_type fields.
50
     */
51
    public function entity()
52
    {
53
        return $this->morphTo();
54
    }
55
56
57
    public function user()
58
    {
59
        $model = User::class;
60
        if (class_exists(\App\Models\User::class)) {
61
            $model = \App\Models\User::class;
62
        }
63
        return $this->belongsTo($model, 'locked_by');
64
    }
65
66
}
67