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

Author   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 0
loc 52
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A books() 0 4 1
A printers() 0 4 1
A profile() 0 4 1
A getLatestBookAttribute() 0 7 1
A scopeStartsWithA() 0 4 1
A scopeNameStartsWith() 0 4 1
A scopeBooksStartWith() 0 4 1
1
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Fixtures;
2
3
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
4
use Illuminate\Database\Eloquent\Builder;
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\HasMany;
7
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
8
use Illuminate\Database\Eloquent\Relations\HasOne;
9
use Illuminate\Database\Eloquent\SoftDeletes;
10
11
class Author extends Model
12
{
13
    use Cachable;
14
    use SoftDeletes;
15
16
    protected $casts = [
17
        "finances" => "array",
18
    ];
19
    protected $fillable = [
20
        'name',
21
        'email',
22
        "finances",
23
    ];
24
25
    public function books() : HasMany
26
    {
27
        return $this->hasMany(Book::class);
28
    }
29
30
    public function printers() : HasManyThrough
31
    {
32
        return $this->hasManyThrough(Printer::class, Book::class);
33
    }
34
    
35
    public function profile() : HasOne
36
    {
37
        return $this->hasOne(Profile::class);
38
    }
39
40
    public function getLatestBookAttribute()
41
    {
42
        return $this
43
            ->books()
44
            ->latest("id")
45
            ->first();
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
    public function scopeBooksStartWith(Builder $query, string $startOfName) : Builder
59
    {
60
        return $query->where("name", "LIKE", "{$startOfName}%");
61
    }
62
}
63