GrantableObserver::saving()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Created on 22/03/18 by enea dhack.
4
 */
5
6
namespace Enea\Authorization\Observers;
7
8
use Enea\Authorization\Support\Determiner;
9
use Illuminate\Database\Eloquent\Model;
10
use Illuminate\Support\Str;
11
12
class GrantableObserver
13
{
14 70
    public function saving(Model $model): void
15
    {
16 70
        if (Determiner::transformSecretNameToKebabCase()) {
17 68
            $name = $model->getAttribute('display_name');
18 68
            $model->setAttribute('secret_name', Str::kebab($name));
0 ignored issues
show
Bug introduced by
It seems like $name can also be of type Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $value of Illuminate\Support\Str::kebab() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
            $model->setAttribute('secret_name', Str::kebab(/** @scrutinizer ignore-type */ $name));
Loading history...
19
        }
20 70
    }
21
}
22