Passed
Push — master ( 9aef17...9e5266 )
by Gabriel
05:26
created

UrlGeneratorFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\MediaLibrary\UrlGenerator;
4
5
use ByTIC\MediaLibrary\Media\Media;
6
use ByTIC\MediaLibrary\Media\Traits\UrlMethodsTrait;
7
use ByTIC\MediaLibrary\PathGenerator\PathGeneratorFactory;
8
9
/**
10
 * Class UrlGeneratorFactory.
11
 */
12
class UrlGeneratorFactory
13
{
14
    /**
15
     * @return BaseUrlGenerator
16
     */
17 1
    public static function create()
18
    {
19 1
        $pathGenerator = PathGeneratorFactory::create();
20
21 1
        $urlGenerator = new BaseUrlGenerator();
22 1
        $urlGenerator->setPathGenerator($pathGenerator);
23 1
        return $urlGenerator;
24
    }
25
26
    /**
27
     * @param Media|UrlMethodsTrait $media
28
     *
29
     * @param string $conversionName
30
     * @return UrlGeneratorInterface|BaseUrlGenerator
31
     * @noinspection PhpDocMissingThrowsInspection
32
     */
33 1
    public static function createForMedia(Media $media, string $conversionName = ''): UrlGeneratorInterface
34
    {
35 1
        $urlGenerator = static::create()
36 1
            ->setMedia($media);
37
38 1
        if (!empty($conversionName)) {
39
            /** @noinspection PhpUnhandledExceptionInspection */
40
            $conversion = $media->getConversions()->getByName($conversionName);
41
42
            $urlGenerator->setConversion($conversion);
43
        }
44
45 1
        return $urlGenerator;
46
    }
47
}
48