Passed
Push — master ( f972fc...fc48d8 )
by Gabriel
03:18
created

UrlMethodsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 6
cp 0
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullUrl() 0 3 1
A getUrl() 0 5 3
1
<?php
2
3
namespace ByTIC\MediaLibrary\Media\Traits;
4
5
use ByTIC\MediaLibrary\UrlGenerator\UrlGeneratorFactory;
6
use function Nip\url;
7
8
/**
9
 * Trait UrlMethodsTrait
10
 * @package ByTIC\MediaLibrary\Media\Traits
11
 */
12
trait UrlMethodsTrait
13
{
14
15
16
    /**
17
     * Get the full url to a original media file.
18
     *
19
     * @param string $conversionName
20
     *
21
     * @return string
22
     */
23
    public function getFullUrl(string $conversionName = ''): string
24
    {
25
        return url()->to($this->getUrl($conversionName));
26
    }
27
28
    /**
29
     * Get the url to a original media file.
30
     *
31
     * @param string $conversionName
32
     *
33
     * @return string
34
     */
35
    public function getUrl(string $conversionName = ''): string
36
    {
37
        $conversionName = $conversionName ? $conversionName : ($this->hasConversion('default') ? 'default' : null);
0 ignored issues
show
Bug introduced by
It seems like hasConversion() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $conversionName = $conversionName ? $conversionName : ($this->/** @scrutinizer ignore-call */ hasConversion('default') ? 'default' : null);
Loading history...
38
        $urlGenerator = UrlGeneratorFactory::createForMedia($this, $conversionName);
0 ignored issues
show
Bug introduced by
It seems like $conversionName can also be of type null; however, parameter $conversionName of ByTIC\MediaLibrary\UrlGe...ctory::createForMedia() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $urlGenerator = UrlGeneratorFactory::createForMedia($this, /** @scrutinizer ignore-type */ $conversionName);
Loading history...
39
        return $urlGenerator->getUrl();
40
    }
41
}