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

UrlGenerator::getResponsiveImagesDirectoryUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 15
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\MediaLibrary;
4
5
use App\Models\Media;
6
use Illuminate\Support\Facades\Route;
7
use Illuminate\Support\Str;
8
use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator;
9
10
class UrlGenerator extends DefaultUrlGenerator
11
{
12
    /**
13
     * Get the url for a media item.
14
     *
15
     * @return string
16
     */
17
    public function getUrl(): string
18
    {
19
        // Collection name.
20
        $collection = $this->media->collection_name;
21
        // Conversion name or set DEFAULT conversion.
22
        $conversion = optional($this->conversion)->getName() ?? 'default';
23
        // Media item.
24
        $media = Media::getEncodedId($this->media->id);
25
        // Item name.
26
        $name = Str::slug($this->media->name);
27
28
        if (Route::has('mediacenter::item.display')) {
29
            return route('mediacenter::item.display', [$collection, $conversion, $media, $name]);
30
        }
31
32
        return 'https://'.config('app.url')."/media/show/{$collection}/{$conversion}/{$media}/{$name}.jpg";
33
    }
34
}
35