DownloadsController::download()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Controllers;
6
7
use Symfony\Component\HttpFoundation\BinaryFileResponse;
8
9
class DownloadsController extends Controller
10
{
11
    /**
12
     * Download a file.
13
     *
14
     * @param string $fileName
15
     *
16
     * @return BinaryFileResponse
17
     */
18
    public function download(string $fileName)
19
    {
20
        $filePath = public_path('files/'.$fileName);
21
22
        if (!file_exists($filePath)) {
23
            abort(404, 'File not found.');
24
        }
25
26
        return response()->download($filePath);
27
    }
28
}
29