BaseExport   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 70
ccs 17
cts 17
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 3 1
A setRange() 0 9 2
A __construct() 0 4 1
A query() 0 3 1
A setModel() 0 5 1
A headings() 0 3 1
1
<?php
2
namespace Distilleries\Expendable\Exports;
3
4
use Carbon\Carbon;
5
use Distilleries\Expendable\Contracts\ExportContract;
6
use Maatwebsite\Excel\Concerns\Exportable;
7
use Maatwebsite\Excel\Concerns\FromQuery;
8
use Maatwebsite\Excel\Concerns\WithHeadings;
9
10
class BaseExport implements FromQuery, WithHeadings, ExportContract
11
{
12
    use Exportable;
0 ignored issues
show
introduced by
The trait Maatwebsite\Excel\Concerns\Exportable requires some properties which are not provided by Distilleries\Expendable\Exports\BaseExport: $disk, $diskOptions, $fileName, $filePath, $writerType, $headers
Loading history...
13
14
    /**
15
     * @var \Distilleries\Expendable\Models\BaseModel
16
     */
17
    private $model;
18
19
    /**
20
     * @var Carbon
21
     */
22
    private $start;
23
24
    /**
25
     * @var Carbon
26
     */
27
    private $end;
28
29 6
    public function __construct($model, $data)
30
    {
31 6
        $this->setModel($model);
32 6
        $this->setRange($data);
33
    }
34
35 6
    public function export($fileName)
36
    {
37 6
        return $this->download($fileName);
38
    }
39
40
    /**
41
     * @return \Illuminate\Database\Query\Builder
42
     */
43 6
    public function query()
44
    {
45 6
        return $this->model->betweenCreate($this->start, $this->end);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->model->bet...his->start, $this->end) also could return the type Illuminate\Database\Eloquent\Builder which is incompatible with the documented return type Illuminate\Database\Query\Builder.
Loading history...
46
    }
47
48
    /**
49
     * @param mixed $model
50
     * @return $this
51
     */
52 6
    public function setModel($model)
53
    {
54 6
        $this->model = $model;
55
56 6
        return $this;
57
    }
58
59
    /**
60
     * @param array $data
61
     * @return $this
62
     */
63 6
    public function setRange($data)
64
    {
65 6
        foreach ($data['range'] as $key => $date)
66
        {
67 6
            Carbon::parse($date);
68 6
            $this->$key = Carbon::parse($date);
69
        }
70
71 6
        return $this;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 6
    public function headings(): array
78
    {
79 6
        return \Illuminate\Support\Facades\Schema::getColumnListing($this->model->getTable());
80
    }
81
}