Passed
Pull Request — 2.x (#586)
by Bekzat
05:24 queued 25s
created

HasRevisions   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 23
ccs 0
cts 10
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeMine() 0 4 1
A revisionsArray() 0 9 1
A revisions() 0 3 1
1
<?php
2
3
namespace A17\Twill\Models\Behaviors;
4
5
trait HasRevisions
6
{
7
    public function revisions()
8
    {
9
        return $this->hasMany(config('twill.namespace') . "\Models\Revisions\\" . class_basename($this) . "Revision")->orderBy('created_at', 'desc');
0 ignored issues
show
Bug introduced by
It seems like hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

9
        return $this->/** @scrutinizer ignore-call */ hasMany(config('twill.namespace') . "\Models\Revisions\\" . class_basename($this) . "Revision")->orderBy('created_at', 'desc');
Loading history...
10
    }
11
12
    public function scopeMine($query)
13
    {
14
        return $query->whereHas('revisions', function ($query) {
15
            $query->where('user_id', auth('twill_users')->user()->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
16
        });
17
    }
18
19
    public function revisionsArray()
20
    {
21
        return $this->revisions->map(function ($revision) {
22
            return [
23
                'id' => $revision->id,
24
                'author' => $revision->user->name ?? 'Unknown',
25
                'datetime' => $revision->created_at->toIso8601String(),
26
            ];
27
        })->toArray();
28
    }
29
}
30