ExporterToExcel::toFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Omatech\Mage\Core\Adapters\Translations\Exporters;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Facades\File;
7
use Omatech\Mage\Core\Domains\Translations\Contracts\ExportTranslationInterface;
8
use Rap2hpoutre\FastExcel\FastExcel;
9
use Rap2hpoutre\FastExcel\SheetCollection;
10
11
class ExporterToExcel implements ExportTranslationInterface
12
{
13
    /**
14
     * @param array $translations
15
     * @return string
16
     */
17 1
    public function export(array $translations): string
18
    {
19 1
        return $this->toFile($translations);
20
    }
21
22
    /**
23
     * @param array $translations
24
     * @return string
25
     */
26 1
    private function toFile(array $translations): string
27
    {
28 1
        $path = base_path('storage/app/translations');
29 1
        File::makeDirectory($path, 0777, true, true);
30
31 1
        $date = Carbon::now('Europe/Madrid')->format('dmY_His');
32 1
        $path = storage_path('app/translations/'.$date.'_excel.xlsx');
33
34
        return (new FastExcel(new SheetCollection($translations)))->export($path, function ($sheets) {
35
            return [
36 1
                'key1'  => 'mage',
37 1
                'key2'  => $sheets['key'],
38 1
                'value' => $sheets['value'],
39
            ];
40 1
        });
41
    }
42
}
43