ExporterToExcel   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 4 1
A toFile() 0 16 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