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

File::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 15
dl 0
loc 21
rs 10

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 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