Passed
Pull Request — 2.x (#1360)
by Harings
11:27
created

BlockEditor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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

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 A17\Twill\View\Components;
4
5
use Illuminate\Support\Str;
6
7
class BlockEditor extends TwillFormComponent
8
{
9
    public $blocks = [];
10
    public $groups = [];
11
    public $group;
12
    public $allowedBlocks;
13
    public $title;
14
    public $trigger;
15
    public $withoutSeparator;
16
17
    public function __construct(
18
        $label = null,
19
        $name = 'default',
20
        $trigger = null,
21
        $title = null,
22
        $blocks = [],
23
        $groups = [],
24
        $group = null,
25
        $withoutSeparator = false
26
    ) {
27
        parent::__construct($name, $label);
28
        $this->trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content');
29
        $this->blocks = $blocks;
30
        $this->groups = $groups;
31
        $this->group = $group;
32
        $this->allowedBlocks = generate_list_of_available_blocks(
33
            $this->blocks ?? null,
34
            $this->group ?? $this->groups ?? null
35
        );
36
        $this->title = $title ?? Str::title($name);
37
        $this->withoutSeparator = $withoutSeparator;
38
    }
39
40
    public function render()
41
    {
42
        return view('twill::partials.form._block_editor', [
43
            'editorName' => [
44
                'label' => $this->title,
45
                'value' => $this->name,
46
            ],
47
        ]);
48
    }
49
}
50