Completed
Push — master ( ce259e...2296bc )
by Elf
01:46
created

EloquentDataTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A addColumns() 0 14 4
1
<?php
2
3
namespace ElfSundae\Laravel\DataTables;
4
5
use Yajra\DataTables\EloquentDataTable as BaseEloquentDataTable;
6
7
class EloquentDataTable extends BaseEloquentDataTable
8
{
9
    /**
10
     * Add columns in collection.
11
     *
12
     * @param  array  $names
13
     * @param  bool|int  $order
14
     * @return $this
15
     */
16
    public function addColumns(array $names, $order = false)
17
    {
18
        foreach ($names as $name => $attribute) {
19
            if (is_int($name)) {
20
                $name = $attribute;
21
            }
22
23
            $this->addColumn($name, function ($model) use ($attribute) {
24
                return $model->getAttribute($attribute);
25
            }, is_int($order) ? $order++ : $order);
26
        }
27
28
        return $this;
29
    }
30
}
31