SetAttribute::setTitleAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
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
{
10 138
    protected function setSlugAttribute($value)
11
    {
12 138
        $value = Str::slug(trim($value), '_');
13
14 138
        $this->setManual('slug', $value);
15 138
    }
16
17 138
    protected function setTitleAttribute($value)
18
    {
19 138
        $this->setManual('title', trim($value));
20 138
    }
21
22 138
    protected function setManual($key, $value)
23
    {
24 138
        $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 138
    }
26
27 12
    protected function getTitleAttribute($value): string
28
    {
29 12
        return $value ?: Str::title($this->slug);
30
    }
31
}
32