MediaLibraryCollectionComponent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 13
dl 0
loc 33
rs 9.7998

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Spatie\MediaLibraryPro\Http\Components;
4
5
use Illuminate\View\Component;
6
use Spatie\MediaLibrary\HasMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\HasMedia was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Spatie\MediaLibraryPro\WithAccessingMedia;
8
9
class MediaLibraryCollectionComponent extends Component
10
{
11
    use WithAccessingMedia;
0 ignored issues
show
introduced by
The trait Spatie\MediaLibraryPro\WithAccessingMedia requires some properties which are not provided by Spatie\MediaLibraryPro\H...raryCollectionComponent: $custom_properties, $timestamp, $size, $file_name, $uuid, $order_column, $created_at, $extension
Loading history...
12
13
    public string $name;
14
    public HasMedia $model;
15
    public string $collection;
16
17
    public string $rules;
18
    public ?int $maxItems;
19
    public bool $sortable;
20
    public bool $editableName = true;
21
22
    public array $media;
23
24
    public ?string $componentView;
25
    public ?string $listView;
26
    public ?string $itemView;
27
    public ?string $propertiesView;
28
    public ?string $fieldsView;
29
30
    public bool $multiple = true;
31
32
    public function __construct(
33
        string $name,
34
        HasMedia $model,
35
        string $collection = null,
36
        string $rules = '',
37
        ?int $maxItems = null,
38
        bool $sortable = true,
39
        bool $editableName = true,
40
        ?string $view = null,
41
        ?string $listView = null,
42
        ?string $itemView = null,
43
        ?string $propertiesView = null,
44
        ?string $fieldsView = null,
45
        bool $multiple = true
46
    ) {
47
        $this->name = $name;
48
        $this->model = $model;
49
        $this->collection = $collection ?? 'default';
50
51
        $this->rules = $rules;
52
        $this->maxItems = $maxItems;
53
        $this->editableName = $editableName;
54
        $this->sortable = $sortable;
55
56
        $this->media = $this->getMedia($name, $model, $this->collection);
57
58
        $this->componentView = $view;
59
        $this->listView = $listView ?? 'media-library::livewire.partials.collection.list';
60
        $this->itemView = $itemView ?? 'media-library::livewire.partials.collection.item';
61
        $this->propertiesView = $propertiesView ?? 'media-library::livewire.partials.collection.properties';
62
        $this->fieldsView = $fieldsView ?? 'media-library::livewire.partials.collection.fields';
63
64
        $this->multiple = $multiple;
65
    }
66
67
    public function render()
68
    {
69
        return view('media-library::components.media-library-collection');
70
    }
71
}
72