Passed
Push — main ( 302427...b5b644 )
by Yaroslav
14:44
created

DownloadExportController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
nc 1
nop 1
dl 0
loc 14
c 1
b 0
f 0
cc 1
ccs 0
cts 9
cp 0
crap 2
rs 10
1
<?php
2
3
namespace NovaExportConfiguration\Http\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use Illuminate\Support\Facades\Storage;
7
use NovaExportConfiguration\Models\ExportStoredFile;
8
9
class DownloadExportController extends Controller
10
{
11
    public function __invoke(string $file): mixed
12
    {
13
        /** @var ExportStoredFile $csvFile */
14
        $csvFile = ExportStoredFile::query()
15
            ->where('path', $file)
16
            ->firstOrFail();
17
18
        $storage = Storage::disk($csvFile->disk);
0 ignored issues
show
Bug introduced by
The property disk does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
19
20
        abort_if(!$storage->exists($csvFile->path), 404);
0 ignored issues
show
Bug introduced by
The property path does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
21
22
        return $storage->download(
23
            $csvFile->path,
24
            preg_replace("/[^a-zA-Z0-9\_\-\.\s]/i", '_', $csvFile->name)
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on NovaExportConfiguration\Models\ExportStoredFile. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
25
        );
26
    }
27
}
28