HasNameAndTitle   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A title() 0 7 2
A name() 0 12 4
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