DownloadExportController   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 1
1
<?php
2
3
namespace NovaResourceDynamicExport\Http\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use Illuminate\Support\Facades\Storage;
7
use NovaResourceDynamicExport\Models\ExportStoredFile;
8
9
class DownloadExportController extends Controller
10
{
11 1
    public function __invoke(string $file): mixed
12
    {
13
        /** @var ExportStoredFile $csvFile */
14 1
        $csvFile = ExportStoredFile::query()
15 1
            ->where('path', $file)
16 1
            ->firstOrFail();
17
18 1
        $storage = Storage::disk($csvFile->disk);
19
20 1
        abort_if(!$storage->exists($csvFile->path), 404);
21
22 1
        return $storage->download(
23 1
            $csvFile->path,
24 1
            preg_replace("/[^a-zA-Z0-9\_\-\.\s]/i", '_', $csvFile->name)
25 1
        );
26
    }
27
}
28