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

Datatable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 13
ccs 0
cts 9
cp 0
crap 2
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
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
use Illuminate\View\Component;
6
7
class Datatable extends Component
8
{
9
    public $beautify;
10
    public $buttons;
11
    public $id;
12
    public $bordered;
13
    public $hoverable;
14
    public $condensed;
15
    public $heads;
16
    public $footer;
17
18
    public function __construct(
19
        $beautify = true, $id,
20
        $bordered = true, $hoverable = true, $condensed = false,
21
        $heads, $footer = false, $buttons = false
22
        ) {
23
        $this->id = $id;
24
        $this->beautify = $beautify;
25
        $this->bordered = $bordered;
26
        $this->hoverable = $hoverable;
27
        $this->condensed = $condensed;
28
        $this->heads = json_decode(json_encode($heads));
29
        $this->footer = $footer;
30
        $this->buttons = $buttons;
31
    }
32
33
    public function border()
34
    {
35
        return ($this->bordered) ? 'table-bordered' : null;
36
    }
37
38
    public function hover()
39
    {
40
        return ($this->hoverable) ? 'table-hover' : null;
41
    }
42
43
    public function condense()
44
    {
45
        return ($this->condensed) ? 'table-condensed' : null;
46
    }
47
48
    public function render()
49
    {
50
        return view('adminlte::components.datatable');
51
    }
52
}
53