Passed
Push — master ( 57971d...267513 )
by Ben
14:57 queued 10s
created

HasDetails::details()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 13
c 2
b 0
f 1
dl 0
loc 20
ccs 13
cts 13
cp 1
rs 9.5222
cc 5
nc 16
nop 0
crap 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 92
     */
14
    public function details(): Details
15
    {
16
        // Generic model details
17 92
        // might be able to remove this as id isnt general info
18 92
        $id = Str::slug($this->registration->key().'-'.$this->model->id);
19 92
        $key = $this->registration->key();
20 92
        $labelSingular = property_exists($this->model, 'labelSingular') ? $this->model->labelSingular : Str::singular($key);
21 92
        $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 92
        // Manager index and header info
25
        $title = $this->model->title ?? ($this->model->id ? $labelSingular . ' ' . $this->model->id : $labelSingular);
26 92
27 92
        return new Details(
28 92
            $id,
29 92
            $key,
30 92
            $labelSingular.'',
31 92
            $labelPlural.'',
32 92
            $internal_label,
33
            $title.''
34
        );
35
    }
36
}
37