ThemeToggle::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 9
dl 0
loc 12
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
declare(strict_types=1);
4
5
namespace Xetaravel\View\Components;
6
7
use Closure;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\View\Component;
10
11
class ThemeToggle extends Component
12
{
13
    public string $uuid;
14
15
    public function __construct(
16
        public ?string $id = null,
17
        public ?string $value = null,
18
        public ?string $light = "Light",
19
        public ?string $dark = "Dark",
20
        public ?string $lightTheme = "light",
21
        public ?string $darkTheme = "dark",
22
        public ?string $lightClass = "light",
23
        public ?string $darkClass = "dark",
24
        public ?bool $withLabel = false,
25
    ) {
26
        $this->uuid = md5(serialize($this)) . $id;
27
    }
28
29
    /**
30
     * Get the view / contents that represent the component.
31
     */
32
    public function render(): View|Closure|string
33
    {
34
        return view('components.theme-toggle');
35
    }
36
}
37