HasNameAndTitle::title()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
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