AsPageSetting   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldsOnIndex() 0 5 1
A fields() 0 12 4
A newModel() 0 3 1
1
<?php
2
3
namespace Thinkone\NovaPageSettings\Nova\Resources\Traits;
4
5
use Laravel\Nova\Fields\ID;
6
use Laravel\Nova\Fields\Text;
7
use Laravel\Nova\Http\Requests\NovaRequest;
8
use Laravel\Nova\Http\Requests\ResourceIndexRequest;
9
use Thinkone\NovaPageSettings\QueryAdapter\InternalSettingsModel;
10
use Thinkone\NovaPageSettings\Templates\SettingsTemplate;
11
12
trait AsPageSetting
13
{
14 2
    public function fields(NovaRequest $request): array
15
    {
16 2
        if (!($request instanceof ResourceIndexRequest)) {
17
            /** @var SettingsTemplate $template */
18 1
            $templateModel = $request->model()->find($request->route('resourceId'));
19 1
            if ($templateModel && ($template = $templateModel->template())) {
20 1
                return $template->fields($request);
21
            }
22
        }
23
24
25 1
        return $this->fieldsOnIndex($request);
26
    }
27
28 1
    public function fieldsOnIndex(ResourceIndexRequest $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

28
    public function fieldsOnIndex(/** @scrutinizer ignore-unused */ ResourceIndexRequest $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...
29
    {
30 1
        return [
31 1
            ID::make('Id', InternalSettingsModel::ATTR_ID),
32 1
            Text::make('Name', InternalSettingsModel::ATTR_NAME),
33 1
        ];
34
    }
35
36 2
    public static function newModel()
37
    {
38 2
        return parent::newModel();
39
    }
40
}
41