Playlist::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Models;
4
5
use App\Traits\CanFilterByUser;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
9
use Illuminate\Support\Collection;
10
11
/**
12
 * @property int        $user_id
13
 * @property Collection $songs
14
 * @property int        $id
15
 * @property array      $rules
16
 * @property bool       $is_smart
17
 * @property string     $name
18
 * @property user       $user
19
 */
20
class Playlist extends Model
21
{
22
    use CanFilterByUser;
23
24
    protected $hidden = ['user_id', 'created_at', 'updated_at'];
25
    protected $guarded = ['id'];
26
    protected $casts = [
27
        'user_id' => 'int',
28
        'rules' => 'array',
29
    ];
30
    protected $appends = ['is_smart'];
31
32 3
    public function songs(): BelongsToMany
33
    {
34 3
        return $this->belongsToMany(Song::class);
35
    }
36
37
    public function user(): BelongsTo
38
    {
39
        return $this->belongsTo(User::class);
40
    }
41
42 4
    public function getIsSmartAttribute(): bool
43
    {
44 4
        return (bool) $this->rules;
45
    }
46
}
47