Passed
Push — master ( 7c331b...3c78de )
by Jonathan
18:06
created

Entity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A creator() 0 3 1
A getRecordAttribute() 0 3 1
A initTablePrefix() 0 3 1
A getModuleAttribute() 0 3 1
1
<?php
2
3
namespace Uccello\Core\Models;
4
5
use Uccello\Core\Database\Eloquent\Model;
6
7
class Entity extends Model
8
{
9
    /**
10
     * The table associated with the model.
11
     *
12
     * @var string
13
     */
14
    protected $table = 'entities';
15
16
    /**
17
     * The attributes that are mass assignable.
18
     *
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'id',
23
        'module_id',
24
        'record_id',
25
        'creator_id',
26
    ];
27
28
    protected $primaryKey = 'id';   // TODO: Change to "uid" to make joins withs modules tables possible ???
29
    public $incrementing = false;
30
31
    // Allow Eloquent to return id as string instead of int.
32
    protected $casts = ['id' => 'string'];
33
34
    protected function initTablePrefix()
35
    {
36
        $this->tablePrefix = env('UCCELLO_TABLE_PREFIX', 'uccello_');
0 ignored issues
show
Bug introduced by
The function env was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        $this->tablePrefix = /** @scrutinizer ignore-call */ env('UCCELLO_TABLE_PREFIX', 'uccello_');
Loading history...
37
    }
38
39
    public function creator()
40
    {
41
        return $this->belongsTo(User::class);
42
    }
43
44
    public function getModuleAttribute()
45
    {
46
        return Module::find($this->module_id);
47
    }
48
49
    public function getRecordAttribute()
50
    {
51
        return $this->module->model_class::find($this->record_id);
52
    }
53
}
54