Passed
Pull Request — 2.x (#586)
by Bekzat
04:25
created

Revision::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 6
rs 10
1
<?php
2
3
namespace A17\Twill\Models;
4
5
use Illuminate\Database\Eloquent\Model as BaseModel;
6
7
abstract class Revision extends BaseModel
8
{
9
    public $timestamps = true;
10
11
    protected $with = ['user'];
12
13
    protected $fillable = [
14
        'payload',
15
        'user_id',
16
    ];
17
18
    public function __construct(array $attributes = [])
19
    {
20
        parent::__construct($attributes);
21
22
        // Remember to update this if you had fields to the fillable array here
23
        // this is to allow child classes to provide a custom foreign key in fillable
24
        if (count($this->fillable) == 2) {
25
            $this->fillable[] = strtolower(str_replace('Revision', '', get_called_class())) . '_id';
26
        }
27
    }
28
29
    public function user()
30
    {
31
        return $this->belongsTo(User::class);
32
    }
33
34
    public function getByUserAttribute()
35
    {
36
        return isset($this->user) ? $this->user->name : 'System';
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on A17\Twill\Models\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
    }
38
}
39