Passed
Push — main ( 030ca0...a21cb6 )
by Mohamed
06:47 queued 03:05
created

UrlController::getResponsiveImagePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Http\Controllers\MediaCenter;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\Media;
7
use Symfony\Component\HttpFoundation\BinaryFileResponse;
8
9
class UrlController extends Controller
10
{
11
    /**
12
     * Display selected media item.
13
     *
14
     * @param  string                                                 $collection
15
     * @param  string                                                 $conversionName
16
     * @param  \App\Models\Media                                      $media
17
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
18
     */
19
    public function display(string $collection, string $conversionName, Media $media): BinaryFileResponse
20
    {
21
        if ($conversionName == 'default') {
22
            $conversionName = '';
23
        }
24
25
        $path = file_exists($path = $this->getFilePath($media, $conversionName))
26
        ? $path : public_path('storage/image.jpg');
27
28
        return response()->file($path);
29
    }
30
31
    /**
32
     * Get the path of the selected media item file.
33
     *
34
     * @param  \App\Models\Media $media
35
     * @return string
36
     */
37
    private function getFilePath(Media $media, $conversionName = ''): string
38
    {
39
        return $media->getPath($conversionName);
40
    }
41
}
42