DataTablesExportHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A collection() 0 4 1
A headings() 0 9 2
1
<?php
2
3
namespace Yajra\DataTables\Services;
4
5
use Illuminate\Support\Collection;
6
use Maatwebsite\Excel\Concerns\Exportable;
7
use Maatwebsite\Excel\Concerns\FromCollection;
8
use Maatwebsite\Excel\Concerns\WithHeadings;
9
10
class DataTablesExportHandler implements FromCollection, WithHeadings
11
{
12
    use Exportable;
13
14
    /**
15
     * @var Collection
16
     */
17
    protected $collection;
18
19
    /**
20
     * DataTablesExportHandler constructor.
21
     *
22
     * @param Collection $collection
23
     */
24
    public function __construct(Collection $collection)
25
    {
26
        $this->collection = $collection;
27
    }
28
29
    /**
30
     * @return Collection
31
     */
32
    public function collection()
33
    {
34
        return $this->collection;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function headings(): array
41
    {
42
        $first = $this->collection->first();
43
        if ($first) {
44
            return array_keys($first);
45
        }
46
47
        return [];
48
    }
49
}
50