HasNameAndTitle::name()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 3
nop 0
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace NovaFlexibleContent\Layouts\LayoutTraits;
4
5
use Illuminate\Support\Str;
6
use Laravel\Nova\Nova;
7
8
trait HasNameAndTitle
9
{
10
    /**
11
     * The layout's unique identifier.
12
     */
13
    protected string $name = '';
14
15
    /**
16
     * The layout's human-readable title.
17
     */
18
    protected string $title = '';
19
20
    /**
21
     * Retrieve the layout's name (identifier)
22
     */
23 23
    public function name(): string
24
    {
25 23
        if($this->name) {
26 16
            return $this->name;
27
        }
28
29 18
        $className = class_basename(static::class);
30 18
        if($className !== 'Layout' && Str::endsWith($className, 'Layout')) {
31 16
            $className = Str::beforeLast($className, 'Layout');
32
        }
33
34 18
        return  Str::snake($className);
35
    }
36
37
    /**
38
     * Retrieve the layout's human-readable title
39
     */
40 16
    public function title(): string
41
    {
42 16
        if($this->title) {
43 8
            return $this->title;
44
        }
45
46 14
        return  Nova::humanize(Str::camel($this->name()));
47
    }
48
}
49