HasAdConfiguration::fieldConfiguration()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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