• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

RonasIT / laravel-helpers / 12489544920

25 Dec 2024 04:53AM UTC coverage: 78.401% (+0.02%) from 78.385%
12489544920

Pull #168

github

web-flow
Merge a36445178 into 338a94856
Pull Request #168: #140 global export mode not affect for email testing

2 of 2 new or added lines in 1 file covered. (100.0%)

1020 of 1301 relevant lines covered (78.4%)

11.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Exporters/Exporter.php
1
<?php
2

3
namespace RonasIT\Support\Exporters;
4

5
use Illuminate\Support\Arr;
6
use Illuminate\Support\Facades\Storage;
7
use Maatwebsite\Excel\Concerns\FromQuery;
8
use Maatwebsite\Excel\Concerns\Exportable;
9
use Maatwebsite\Excel\Concerns\WithMapping;
10
use Maatwebsite\Excel\Concerns\WithHeadings;
11
use RonasIT\Support\Interfaces\ExporterInterface;
12

13
abstract class Exporter implements FromQuery, WithHeadings, WithMapping, ExporterInterface
14
{
15
    use Exportable;
16

17
    protected $disk;
18
    protected $query;
19
    protected $fileName;
20
    protected $type = 'csv';
21

22
    public function __construct()
23
    {
24
        $this->disk = config('filesystems.default', 'local');
×
25
    }
26

27
    public function setQuery($query): self
28
    {
29
        $this->query = $query;
×
30

31
        return $this;
×
32
    }
33

34
    public function setDisk($disk): self
35
    {
36
        $this->disk = $disk;
×
37

38
        return $this;
×
39
    }
40

41
    public function setFileName(string $fileName): self
42
    {
43
        $this->fileName = $fileName;
×
44

45
        return $this;
×
46
    }
47

48
    /**
49
     * @param $type string default: csv, should be one of presented here https://docs.laravel-excel.com/3.0/exports/export-formats.html
50
     *
51
     * @return $this
52
     */
53
    public function setType(string $type): self
54
    {
55
        $this->type = $type;
×
56

57
        return $this;
×
58
    }
59

60
    public function export(): string
61
    {
62
        $filename = $this->getFileName();
×
63

64
        $this->store($filename, $this->disk, ucfirst($this->type));
×
65

66
        return Storage::disk($this->disk)->path($filename);
×
67
    }
68

69
    public function query()
70
    {
71
        return $this->query;
×
72
    }
73

74
    public function headings(): array
75
    {
76
        return Arr::isAssoc($this->getFields()) ? array_keys($this->getFields()) : $this->getFields();
×
77
    }
78

79
    public function map($row): array
80
    {
81
        return array_map(function ($fieldName) use ($row) {
×
82
            return Arr::get($row, $fieldName);
×
83
        }, $this->getFields());
×
84
    }
85

86
    abstract public function getFields(): array;
87

88
    protected function getFileName(): string
89
    {
90
        $this->fileName = empty($this->fileName) ? uniqid() : $this->fileName;
×
91

92
        return "{$this->fileName}.{$this->type}";
×
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc