HasFieldsCollection::filterForDetail()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace NovaFlexibleContent\Layouts\LayoutTraits;
4
5
use Laravel\Nova\Fields\FieldCollection;
6
use Laravel\Nova\Http\Requests\NovaRequest;
7
8
trait HasFieldsCollection
9
{
10
    /**
11
     * The layout's registered fields.
12
     */
13
    protected ?FieldCollection $fields = null;
14
15
    /**
16
     * Provided by developer fields.
17
     */
18 2
    protected function fields(): array
19
    {
20 2
        return $this->fields ? $this->fields->all() : [];
21
    }
22
23
    /**
24
     * Retrieve the layout's fields as a collection.
25
     */
26 17
    public function fieldsCollection(): FieldCollection
27
    {
28 17
        $fields = $this->fields;
29 17
        if(!$fields || $fields->isEmpty()) {
30 17
            $fields = $this->fields();
31
        }
32
33 17
        return FieldCollection::make($fields);
0 ignored issues
show
Bug introduced by
It seems like $fields can also be of type array; however, parameter $items of Illuminate\Support\Collection::make() does only seem to accept Illuminate\Contracts\Support\Arrayable, maybe add an additional type check? ( Ignorable by Annotation )

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

33
        return FieldCollection::make(/** @scrutinizer ignore-type */ $fields);
Loading history...
34
    }
35
36
    /**
37
     * Filter the layout's fields for detail view.
38
     */
39 1
    public function filterForDetail(NovaRequest $request, mixed $resource): static
40
    {
41 1
        $this->fields = $this->fieldsCollection()->filterForDetail($request, $resource);
42
43 1
        return $this;
44
    }
45
}
46