Completed
Push — master ( f67f4f...77dcfd )
by Curtis
40s queued 12s
created

HasAvatar   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 17
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateAvatar() 0 5 1
A avatar() 0 3 1
A bootHasAvatar() 0 3 1
1
<?php
2
3
namespace App\Traits\enso\avatars;
4
5
use App\Models\enso\Avatars\Avatar;
6
use App\Service\enso\avatars\DefaultAvatar;
7
8
trait HasAvatar
9
{
10
    public static function bootHasAvatar()
11
    {
12
        self::created(fn ($model) => $model->generateAvatar());
13
    }
14
15
    public function avatar()
16
    {
17
        return $this->hasOne(Avatar::class);
0 ignored issues
show
Bug introduced by
It seems like hasOne() 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

17
        return $this->/** @scrutinizer ignore-call */ hasOne(Avatar::class);
Loading history...
18
    }
19
20
    public function generateAvatar(): Avatar
21
    {
22
        optional($this->avatar)->delete();
23
24
        return (new DefaultAvatar($this))->create();
25
    }
26
}
27