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

Revision   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 30
ccs 0
cts 9
cp 0
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 1
A getByUserAttribute() 0 3 2
A __construct() 0 8 2
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