MediaLibraryAttachmentComponent   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A determineItemViewName() 0 7 2
A determineFieldsViewName() 0 7 2
A render() 0 3 1
A determineMaxItems() 0 5 2
A determineListViewName() 0 7 2
1
<?php
2
3
namespace Spatie\MediaLibraryPro\Http\Components;
4
5
use Illuminate\View\Component;
6
7
class MediaLibraryAttachmentComponent extends Component
8
{
9
    public array $media;
10
11
    public ?string $propertiesView = null;
12
13
    public function __construct(
14
        public string $name,
15
        public string $rules = '',
16
        public $multiple = false,
17
        public $editableName = false,
18
        public ?int $maxItems = null,
19
        public ?string $componentView = null,
20
        public ?string $listView = null,
21
        public ?string $itemView = null,
22
        ?string $propertiesView = null,
23
        public ?string $fieldsView = null
24
    ) {
25
        $this->media = old($name) ?? [];
26
        $this->propertiesView = $propertiesView ?? 'media-library::livewire.partials.attachment.properties';
27
    }
28
29
    public function render()
30
    {
31
        return view('media-library::components.media-library-attachment');
32
    }
33
34
    public function determineListViewName(): string
35
    {
36
        if (! is_null($this->listView)) {
37
            return $this->listView;
38
        }
39
40
        return 'media-library::livewire.partials.attachment.list';
41
    }
42
43
    public function determineItemViewName(): string
44
    {
45
        if (! is_null($this->itemView)) {
46
            return $this->itemView;
47
        }
48
49
        return 'media-library::livewire.partials.attachment.item';
50
    }
51
52
    public function determineFieldsViewName(): string
53
    {
54
        if (! is_null($this->fieldsView)) {
55
            return $this->fieldsView;
56
        }
57
58
        return 'media-library::livewire.partials.attachment.fields';
59
    }
60
61
    public function determineMaxItems(): ?int
62
    {
63
        return $this->multiple
64
            ? $this->maxItems
65
            : 1;
66
    }
67
}
68