Passed
Pull Request — master (#721)
by Florian
02:40
created

TextEditor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 11
dl 0
loc 18
ccs 0
cts 12
cp 0
crap 2
rs 9.9

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 JeroenNoten\LaravelAdminLte\Components;
4
5
use Illuminate\View\Component;
6
7
class TextEditor extends Component
8
{
9
    public $id;
10
    public $name;
11
    public $label;
12
    public $placeholder;
13
    public $topclass;
14
    public $inputclass;
15
    public $body;
16
    public $disabled;
17
    public $required;
18
    public $height;
19
    public $fonts;
20
    public $def_fonts = ['Arial', 'Arial Black', 'Comic Sans MS', 'Courier New', 'Impact', 'Montserrat',  'Open Sans', 'Ubuntu', 'Rajdhani'];
21
22
    public function __construct(
23
            $id, $name = null,
24
            $label = 'Input Label', $placeholder = null,
25
            $topclass = null, $inputclass = null,
26
            $body = null, $disabled = false, $required = false,
27
            $height = 500, $fonts = null
28
        ) {
29
        $this->id = $id;
30
        $this->name = $name;
31
        $this->label = $label;
32
        $this->placeholder = $placeholder;
33
        $this->topclass = $topclass;
34
        $this->inputclass = $inputclass;
35
        $this->body = $body;
36
        $this->required = $required;
37
        $this->disabled = $disabled;
38
        $this->height = $height;
39
        $this->fonts = $fonts;
40
    }
41
42
    public function fontarray()
43
    {
44
        return $this->fonts == null ? json_encode($this->def_fonts) : $this->fonts;
45
    }
46
47
    public function render()
48
    {
49
        return view('adminlte::components.text-editor');
50
    }
51
}
52