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

BlockEditor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
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 10
dl 0
loc 23
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
        $renderForBlocks = false,
21
        $renderForModal = false,
22
        $trigger = null,
23
        $title = null,
24
        $blocks = [],
25
        $groups = [],
26
        $group = null,
27
        $withoutSeparator = false
28
    ) {
29
        parent::__construct($name, $label, $renderForBlocks, $renderForModal);
30
        $this->trigger = $trigger ?? $label ?? twillTrans('twill::lang.fields.block-editor.add-content');
31
        $this->blocks = $blocks;
32
        $this->groups = $groups;
33
        $this->group = $group;
34
        $this->allowedBlocks = generate_list_of_available_blocks(
35
            $this->blocks ?? null,
36
            $this->group ?? $this->groups ?? null
37
        );
38
        $this->title = $title ?? Str::title($name);
39
        $this->withoutSeparator = $withoutSeparator;
40
    }
41
42
    public function render()
43
    {
44
        return view('twill::partials.form._block_editor', [
45
            'editorName' => [
46
                'label' => $this->title,
47
                'value' => $this->name,
48
            ],
49
        ]);
50
    }
51
}
52