Completed
Pull Request — master (#372)
by Mike
31:01 queued 16:07
created

UncachedAuthor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A books() 0 4 1
A getLatestBookAttribute() 0 7 1
A printers() 0 4 1
A profile() 0 4 1
A scopeStartsWithA() 0 4 1
A scopeNameStartsWith() 0 4 1
1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
2
3
use Illuminate\Database\Eloquent\Builder;
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Database\Eloquent\Relations\HasMany;
6
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
7
use Illuminate\Database\Eloquent\Relations\HasOne;
8
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
9
use Illuminate\Database\Eloquent\SoftDeletes;
10
11
class UncachedAuthor extends Model
12
{
13
    use SoftDeletes;
14
    
15
    protected $casts = [
16
        "finances" => "array",
17
    ];
18
    protected $fillable = [
19
        'name',
20
        'email',
21
        "finances",
22
    ];
23
    protected $table = 'authors';
24
25
    public function books() : HasMany
26
    {
27
        return $this->hasMany(UncachedBook::class, 'author_id', 'id');
28
    }
29
30
    public function getLatestBookAttribute()
31
    {
32
        return $this
33
            ->books()
34
            ->latest("id")
35
            ->first();
36
    }
37
38
    public function printers() : HasManyThrough
39
    {
40
        return $this->hasManyThrough(Printer::class, Book::class, "author_id");
41
    }
42
43
    public function profile() : HasOne
44
    {
45
        return $this->hasOne(UncachedProfile::class, 'author_id', 'id');
46
    }
47
48
    public function scopeStartsWithA(Builder $query) : Builder
49
    {
50
        return $query->where('name', 'LIKE', 'A%');
51
    }
52
53
    public function scopeNameStartsWith(Builder $query, string $startOfName) : Builder
54
    {
55
        return $query->where("name", "LIKE", "{$startOfName}%");
56
    }
57
}
58