Completed
Push — master ( 279d4e...5d09e0 )
by Elf
02:49
created

Builder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 37.93 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 22
loc 58
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tableId() 0 4 1
A stripedTable() 11 11 2
A hoveredTable() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace ElfSundae\Laravel\Support\Datatables\Html;
4
5
use Yajra\Datatables\Html\Builder as BaseBuilder;
6
7
class Builder extends BaseBuilder
8
{
9
    /**
10
     * Table attributes.
11
     *
12
     * @var array
13
     */
14
    protected $tableAttributes = [
15
        'id' => 'dataTable',
16
        'class' => 'table table-bordered table-hover dt-responsive',
17
        'width' => '100%',
18
    ];
19
20
    /**
21
     * Set table "id" attribute.
22
     *
23
     * @param  string  $id
24
     * @return $this
25
     */
26
    public function tableId($id)
27
    {
28
        return $this->setTableAttribute('id', $id);
29
    }
30
31
    /**
32
     * Change table style to striped.
33
     *
34
     * @return $this
35
     */
36 View Code Duplication
    public function stripedTable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        if (! str_contains($this->tableAttributes['class'], 'table-striped')) {
39
            $this->tableAttributes['class'] = str_replace(
40
                'table-hover', '',
41
                $this->tableAttributes['class'].' table-striped'
42
            );
43
        }
44
45
        return $this;
46
    }
47
48
    /**
49
     * Change table style to hovered.
50
     *
51
     * @return $this
52
     */
53 View Code Duplication
    public function hoveredTable()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        if (! str_contains($this->tableAttributes['class'], 'table-hover')) {
56
            $this->tableAttributes['class'] = str_replace(
57
                'table-striped', '',
58
                $this->tableAttributes['class'].' table-hover'
59
            );
60
        }
61
62
        return $this;
63
    }
64
}
65