Issues (215)

src/Model/Traits/HasProperty.php (2 issues)

1
<?php
2
3
namespace Siak\Tontine\Model\Traits;
4
5
use Illuminate\Database\Eloquent\Casts\Attribute;
6
use Siak\Tontine\Model\Property;
7
8
trait HasProperty
9
{
10
    /**
11
     * Get the property model.
12
     */
13
    public function property()
14
    {
15
        return $this->morphOne(Property::class, 'owner');
0 ignored issues
show
It seems like morphOne() 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

15
        return $this->/** @scrutinizer ignore-call */ morphOne(Property::class, 'owner');
Loading history...
16
    }
17
18
    /**
19
     * Get the values of the properties.
20
     *
21
     * @return Attribute
22
     */
23
    protected function properties(): Attribute
24
    {
25
        return Attribute::make(
26
            get: fn() => $this->property?->content ?? [],
27
        );
28
    }
29
30
    /**
31
     * Save the values of the properties.
32
     *
33
     * @param array $content
34
     *
35
     * @return void
36
     */
37
    public function saveProperties(array $content)
38
    {
39
        $this->property ? $this->property->update(['content' => $content]) :
40
            $this->property()->create(['content' => $content]);
41
        // Refresh the relation;
42
        $this->load('property');
0 ignored issues
show
It seems like load() 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

42
        $this->/** @scrutinizer ignore-call */ 
43
               load('property');
Loading history...
43
    }
44
}
45