NavigationDataTable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 22.64 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
dl 24
loc 106
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ajax() 0 14 1
A query() 0 6 1
A html() 8 8 1
A getColumns() 0 22 1
A getBuilderParameters() 16 16 1
A filename() 0 4 1

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 Yajra\CMS\DataTables;
4
5
use Yajra\CMS\Entities\Navigation;
6
use Yajra\Datatables\Services\DataTable;
7
8
class NavigationDataTable extends DataTable
9
{
10
    /**
11
     * Display ajax response.
12
     *
13
     * @return \Illuminate\Http\JsonResponse
14
     */
15
    public function ajax()
16
    {
17
        return $this->datatables
18
            ->eloquent($this->query())
19
            ->addColumn('action', 'administrator.navigation.datatables.action')
20
            ->addColumn('menus', function (Navigation $nav) {
21
                return '<span class="badge label-primary">' . $nav->menus()->count() . '</span>';
22
            })
23
            ->rawColumns(['menus', 'published', 'action'])
24
            ->editColumn('published', function (Navigation $row) {
25
                return dt_check($row->published);
26
            })
27
            ->make(true);
28
    }
29
30
    /**
31
     * Get the query object to be processed by datatables.
32
     *
33
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
34
     */
35
    public function query()
36
    {
37
        $users = Navigation::query();
38
39
        return $this->applyScopes($users);
40
    }
41
42
    /**
43
     * Optional method if you want to use html builder.
44
     *
45
     * @return \Yajra\Datatables\Html\Builder
46
     */
47 View Code Duplication
    public function html()
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...
48
    {
49
        return $this->builder()
50
                    ->columns($this->getColumns())
51
                    ->ajax('')
52
                    ->addAction(['width' => '150px', 'className' => 'text-center'])
53
                    ->parameters($this->getBuilderParameters());
54
    }
55
56
    /**
57
     * Get columns.
58
     *
59
     * @return array
60
     */
61
    private function getColumns()
62
    {
63
        return [
64
            'id'         => ['width' => '20px'],
65
            'title',
66
            'type'       => ['width' => '80px'],
67
            'menus'      => [
68
                'orderable'  => false,
69
                'name'       => 'menus',
70
                'searchable' => false,
71
                'width'      => '25px',
72
                'title'      => '<i class="fa fa-clone" data-toggle="tooltip" data-title="' . trans('cms::navigation.datatable.columns.menus') . '"></i>',
73
            ],
74
            'published'  => [
75
                'name'  => 'published',
76
                'width' => '20px',
77
                'title' => '<i class="fa fa-check-circle" data-toggle="tooltip" data-title="' . trans('cms::navigation.datatable.columns.published') . '"></i>',
78
            ],
79
            'created_at' => ['width' => '120px'],
80
            'updated_at' => ['width' => '120px'],
81
        ];
82
    }
83
84
    /**
85
     * @return array
86
     */
87 View Code Duplication
    protected function getBuilderParameters()
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...
88
    {
89
        return [
90
            'stateSave' => true,
91
            'buttons'   => [
92
                [
93
                    'extend' => 'create',
94
                    'text'   => '<i class="fa fa-plus"></i>&nbsp;&nbsp;' . trans('cms::navigation.datatable.buttons.create'),
95
                ],
96
                'export',
97
                'print',
98
                'reset',
99
                'reload',
100
            ],
101
        ];
102
    }
103
104
    /**
105
     * Get filename for export.
106
     *
107
     * @return string
108
     */
109
    protected function filename()
110
    {
111
        return 'navigation';
112
    }
113
}
114