Passed
Push — ft/fields-refactor ( 4da40d...81b991 )
by Ben
119:47 queued 110:11
created

HasDetails   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 14
c 2
b 0
f 1
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A details() 0 20 5
1
<?php
2
3
namespace Thinktomorrow\Chief\Management\Details;
4
5
use Illuminate\Support\Str;
6
use Thinktomorrow\Chief\FlatReferences\ProvidesFlatReference;
7
8
trait HasDetails
9
{
10
    /**
11
     * Details of the model such as naming, key and class.
12
     * Used in several dynamic parts of the admin application.
13 107
     */
14
    public function details(): Details
15
    {
16
        // Generic model details
17 107
        // might be able to remove this as id isnt general info
18 107
        $id = Str::slug($this->registration->key().'-'.$this->model->id);
19 107
        $key = $this->registration->key();
20 107
        $labelSingular = property_exists($this->model, 'labelSingular') ? $this->model->labelSingular : Str::singular($key);
21 107
        $labelPlural = property_exists($this->model, 'labelPlural') ? $this->model->labelPlural : Str::plural($key);
22
        $internal_label = contract($this->model, ProvidesFlatReference::class) ? $this->model->flatReferenceLabel() : $key;
23
24 107
        // Manager index and header info
25
        $title = $this->model->title ?? ($this->model->id ? $labelSingular . ' ' . $this->model->id : $labelSingular);
26 107
27 107
        return new Details(
28 107
            $id,
29 107
            $key,
30 107
            $labelSingular.'',
31 107
            $labelPlural.'',
32 107
            $internal_label,
33
            $title.''
34
        );
35
    }
36
}
37