UrlGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 23
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 16 2
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