TextEditor::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 11
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 2
rs 10
c 0
b 0
f 0

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\View\Components\Form;
4
5
class TextEditor extends InputGroupComponent
6
{
7
    use Traits\OldValueSupportTrait;
8
9
    /**
10
     * The Summernote plugin configuration parameters. Array with 'key => value'
11
     * pairs, where the key should be an existing configuration property of
12
     * the plugin.
13
     *
14
     * @var array
15
     */
16
    public $config;
17
18
    /**
19
     * Create a new component instance.
20
     * Note this component requires the 'Summernote' plugin.
21
     * TODO: the append/prepend addon slots are not supported.
22
     *
23
     * @return void
24
     */
25 3
    public function __construct(
26
        $name, $id = null, $label = null, $igroupSize = null, $labelClass = null,
27
        $fgroupClass = null, $igroupClass = null, $disableFeedback = null,
28
        $errorKey = null, $config = [], $enableOldSupport = null
29
    ) {
30 3
        parent::__construct(
31 3
            $name, $id, $label, $igroupSize, $labelClass, $fgroupClass,
32 3
            $igroupClass, $disableFeedback, $errorKey
33 3
        );
34
35 3
        $this->config = is_array($config) ? $config : [];
36 3
        $this->enableOldSupport = isset($enableOldSupport);
37
38
        // Setup the default plugin width option.
39
40 3
        $this->config['width'] = $this->config['width'] ?? 'inherit';
41
    }
42
43
    /**
44
     * Make the class attribute for the "input-group" element. Note we overwrite
45
     * the method of the parent class.
46
     *
47
     * @return string
48
     */
49 1
    public function makeInputGroupClass()
50
    {
51 1
        $classes = ['input-group'];
52
53 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
54 1
            $classes[] = "input-group-{$this->size}";
55
        }
56
57 1
        if ($this->isInvalid()) {
58 1
            $classes[] = 'adminlte-invalid-itegroup';
59
        }
60
61 1
        if (isset($this->igroupClass)) {
62 1
            $classes[] = $this->igroupClass;
63
        }
64
65 1
        return implode(' ', $classes);
66
    }
67
68
    /**
69
     * Get the view / contents that represent the component.
70
     *
71
     * @return \Illuminate\View\View|string
72
     */
73 1
    public function render()
74
    {
75 1
        return view('adminlte::components.form.text-editor');
76
    }
77
}
78