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

UrlMethodsTrait::getUrl()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 12
rs 10
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
}