ConfiguredExport   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 49
ccs 0
cts 20
cp 0
rs 10
c 1
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setChunkSize() 0 5 1
A registerEvents() 0 15 3
A query() 0 3 1
A chunkSize() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace NovaExportConfiguration\Export;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Facades\Log;
7
use Maatwebsite\Excel\Concerns\Exportable;
8
use Maatwebsite\Excel\Concerns\FromQuery;
9
use Maatwebsite\Excel\Concerns\WithCustomChunkSize;
10
use Maatwebsite\Excel\Concerns\WithEvents;
11
use Maatwebsite\Excel\Concerns\WithHeadings;
12
use Maatwebsite\Excel\Concerns\WithMapping;
13
use Maatwebsite\Excel\Events\AfterSheet;
14
use NovaResourceDynamicExport\Export\HasFileModel;
15
use NovaResourceDynamicExport\Export\WithNotification;
16
17
abstract class ConfiguredExport implements FromQuery, WithMapping, WithEvents, WithHeadings, WithCustomChunkSize
18
{
19
    use Exportable, HasFileModel, WithNotification;
0 ignored issues
show
introduced by
The trait Maatwebsite\Excel\Concerns\Exportable requires some properties which are not provided by NovaExportConfiguration\Export\ConfiguredExport: $disk, $diskOptions, $fileName, $filePath, $writerType, $headers
Loading history...
introduced by
The trait NovaResourceDynamicExport\Export\WithNotification requires some properties which are not provided by NovaExportConfiguration\Export\ConfiguredExport: $name, $download_link, $exists
Loading history...
20
21
    protected ExportQuery $exportQuery;
22
23
    protected int $chunkSize = 500;
24
25
    public function __construct(ExportQuery $exportQuery)
26
    {
27
        $this->exportQuery = $exportQuery;
28
    }
29
30
    abstract public function headings(): array;
31
32
    abstract public function map($row): array;
33
34
    public function query()
35
    {
36
        return $this->exportQuery->query();
37
    }
38
39
    public function setChunkSize(int $chunkSize): static
40
    {
41
        $this->chunkSize = $chunkSize;
42
43
        return $this;
44
    }
45
46
    public function chunkSize(): int
47
    {
48
        return $this->chunkSize;
49
    }
50
51
    public function registerEvents(): array
52
    {
53
        return [
54
            AfterSheet::class => function (AfterSheet $event) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

54
            AfterSheet::class => function (/** @scrutinizer ignore-unused */ AfterSheet $event) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
                try {
56
                    $this->exportQuery->getConfigurationModel()->update([
57
                        'last_export_at' => Carbon::now(),
58
                    ]);
59
                } catch (\Exception $e) {
60
                    Log::error($e->getMessage());
61
                }
62
63
                $fileModel = $this->saveFileFromModel();
64
                if($fileModel?->exists) {
65
                    $this->notifyUser($fileModel);
66
                }
67
            },
68
        ];
69
    }
70
}
71