Passed
Push — master ( ca020b...6b9629 )
by Andrey
13:56
created

SetAttribute::setManual()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helldar\Roles\Traits;
4
5
use Illuminate\Support\Str;
6
7
/** @mixin \Illuminate\Database\Eloquent\Model */
8
trait SetAttribute
9 48
{
10
    protected function setSlugAttribute($value)
11 48
    {
12
        $value = Str::of($value)->trim()->slug('_');
13 48
14 48
        $this->setManual('slug', $value);
15
    }
16 48
17
    protected function setTitleAttribute($value)
18 48
    {
19 48
        $this->setManual('title', trim($value));
20
    }
21
22
    protected function setManual($key, $value)
23
    {
24
        $this->attributes[$key] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
    }
26
27
    protected function getTitleAttribute($value): string
28
    {
29
        return $value ?: Str::of($this->slug)->title()->trim();
30
    }
31
}
32