Test Failed
Push — ft/states ( 7e5f34...a5a3f4 )
by Ben
06:21
created

HasDetails::details()   B

Complexity

Conditions 8
Paths 64

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 19
c 2
b 0
f 1
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 8.4444
cc 8
nc 64
nop 0
crap 8
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
     */
14 146
    public function details(): Details
15
    {
16
        $className = ($this->modelClass());
0 ignored issues
show
Bug introduced by
It seems like modelClass() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        /** @scrutinizer ignore-call */ 
17
        $className = ($this->modelClass());
Loading history...
17
        $genericModelInstance = new $className;
18 146
19 146
        // Generic model details
20 146
        $id = Str::slug($this->registration->key(). ($this->hasExistingModel() ? '-'. $this->existingModel()->id : ''));
0 ignored issues
show
Bug introduced by
It seems like hasExistingModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $id = Str::slug($this->registration->key(). ($this->/** @scrutinizer ignore-call */ hasExistingModel() ? '-'. $this->existingModel()->id : ''));
Loading history...
Bug introduced by
It seems like existingModel() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $id = Str::slug($this->registration->key(). ($this->hasExistingModel() ? '-'. $this->/** @scrutinizer ignore-call */ existingModel()->id : ''));
Loading history...
21 146
        $key = $this->registration->key();
22 146
        $labelSingular = property_exists($genericModelInstance, 'labelSingular') ? $genericModelInstance->labelSingular : Str::singular($key);
23
        $labelPlural = property_exists($genericModelInstance, 'labelPlural') ? $genericModelInstance->labelPlural : Str::plural($key);
24
        $internal_label = ($this->hasExistingModel() && contract($this->model, ProvidesFlatReference::class))
25 146
            ? $this->existingModel()->flatReferenceLabel()
26
            : $key;
27 146
28 146
        // Manager index and header info
29 146
        $title = ($this->hasExistingModel() && $this->existingModel()->title)
30 146
            ? $this->existingModel()->title
31 146
            : $labelSingular;
32 146
33 146
        return new Details(
34
            $id,
35
            $key,
36
            $labelSingular.'',
37
            $labelPlural.'',
38
            $internal_label,
39
            $title.''
40
        );
41
    }
42
}
43