HasAdConfiguration   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 31
c 1
b 0
f 0
dl 0
loc 61
ccs 0
cts 38
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldID() 0 3 1
A label() 0 3 1
A fieldStatus() 0 9 1
A fieldKey() 0 7 1
A fieldLocation() 0 6 1
A fieldConfiguration() 0 10 2
A fields() 0 8 1
1
<?php
2
3
namespace NovaAdDirector\Nova\Resources;
4
5
use Illuminate\Http\Request;
6
use Laravel\Nova\Fields\Field;
7
use Laravel\Nova\Fields\ID;
8
use Laravel\Nova\Fields\Select;
9
use Laravel\Nova\Fields\Text;
10
use NovaAdDirector\NovaAdDirector;
11
use NovaFlexibleContent\Flexible;
12
13
trait HasAdConfiguration
14
{
15
    public static function label()
16
    {
17
        return trans('nova-ad-director::resource.label');
18
    }
19
20
    public function fields(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

20
    public function fields(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        return [
23
            $this->fieldID(),
24
            $this->fieldKey(),
25
            $this->fieldLocation(),
26
            $this->fieldStatus(),
27
            $this->fieldConfiguration(),
28
        ];
29
    }
30
31
    public function fieldID(): Field
32
    {
33
        return ID::make()->sortable();
34
    }
35
36
    public function fieldKey(): Field
37
    {
38
        return Text::make(trans('nova-ad-director::resource.fields.key'), 'key')
39
                   ->sortable()
40
                   ->placeholder(implode(NovaAdDirector::$fallbackKeyConnector, ['header', 'page', 'contact']))
41
                   ->rules('required', 'regex:/^[a-z0-9_\-'.NovaAdDirector::$fallbackKeyConnector.']+$/i', 'max:150')
42
                   ->readonly(!config('nova-ad-director.creatable'));
43
    }
44
45
    public function fieldLocation(): Field
46
    {
47
        return Text::make(trans('nova-ad-director::resource.fields.location'), 'location')
48
                   ->sortable()
49
                   ->rules('required', 'regex:/^[a-z0-9_-]+$/i', 'max:150')
50
                   ->readonly(!config('nova-ad-director.creatable'));
51
    }
52
53
    public function fieldStatus(): Field
54
    {
55
        return Select::make(trans('nova-ad-director::resource.fields.status'), 'status')
56
                     ->options(collect(config('nova-ad-director.statuses'))
57
                         ->mapWithKeys(fn ($status) => [$status => trans("nova-ad-director::resource.statuses.{$status}")])
58
                         ->toArray())
59
                     ->displayUsingLabels()
60
                     ->sortable()
61
                     ->rules('required');
62
    }
63
64
    public function fieldConfiguration(): Field
65
    {
66
        $field = Flexible::make('Configuration', 'configuration')
67
                         ->limit()
68
                         ->rules('required');
69
        foreach (config('nova-ad-director.flexible.configuration.layouts') as $layout) {
70
            $field->addLayout($layout);
0 ignored issues
show
Deprecated Code introduced by
The function NovaFlexibleContent\Flexible::addLayout() has been deprecated: Please use alternative useLayout ( Ignorable by Annotation )

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

70
            /** @scrutinizer ignore-deprecated */ $field->addLayout($layout);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
71
        }
72
73
        return $field;
74
    }
75
}
76