Passed
Push — 5.0.0 ( f10804...44b42e )
by Fèvre
15:04 queued 07:40
created

File   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A modelName() 0 3 1
A render() 0 3 1
A errorFieldName() 0 3 1
A __construct() 0 21 1
A cropSetup() 0 7 1
1
<?php
2
3
namespace Xetaravel\View\Components;
4
5
use Closure;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\View\Component;
8
9
class File extends Component
10
{
11
    public string $uuid;
12
13
    public function __construct(
14
        public ?string $id = null,
15
        public ?string $label = null,
16
        public ?string $hint = null,
17
        public ?string $hintClass = 'fieldset-label',
18
        public ?bool $hideProgress = false,
19
        public ?bool $cropAfterChange = false,
20
        public ?string $changeText = "Change",
21
        public ?string $cropTitleText = "Crop image",
22
        public ?string $cropCancelText = "Cancel",
23
        public ?string $cropSaveText = "Crop",
24
        public ?array $cropConfig = [],
25
        public ?string $cropMimeType = "image/png",
26
27
        // Validations
28
        public ?string $errorClass = 'text-error',
29
        public ?bool $omitError = false,
30
        public ?bool $firstErrorOnly = false,
31
32
    ) {
33
        $this->uuid = md5(serialize($this)) . $id;
34
    }
35
36
    public function modelName(): ?string
37
    {
38
        return $this->attributes->whereStartsWith('wire:model')->first();
39
    }
40
41
    public function errorFieldName(): ?string
42
    {
43
        return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first();
44
    }
45
46
    public function cropSetup(): string
47
    {
48
        return json_encode(array_merge([
49
            'autoCropArea' => 1,
50
            'viewMode' => 1,
51
            'dragMode' => 'move'
52
        ], $this->cropConfig));
0 ignored issues
show
Bug introduced by
It seems like $this->cropConfig can also be of type null; however, parameter $arrays of array_merge() does only seem to accept array, 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

52
        ], /** @scrutinizer ignore-type */ $this->cropConfig));
Loading history...
53
    }
54
55
    /**
56
     * Get the view / contents that represent the component.
57
     */
58
    public function render(): View|Closure|string
59
    {
60
        return view('components.file');
61
    }
62
}
63