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

AbstractUrlGenerator::setConversion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace ByTIC\MediaLibrary\UrlGenerator;
4
5
use ByTIC\MediaLibrary\Conversions\Conversion;
6
use ByTIC\MediaLibrary\Media\Media;
7
use ByTIC\MediaLibrary\PathGenerator\AbstractPathGenerator;
8
use League\Flysystem\FilesystemInterface;
9
10
/**
11
 * Class AbstractUrlGenerator
12
 * @package ByTIC\MediaLibrary\UrlGenerator
13
 */
14
class AbstractUrlGenerator implements UrlGeneratorInterface
15
{
16
17
    /**
18
     * @var Media
19
     */
20
    protected $media;
21
22
    /**
23
     * @var Conversion
24
     */
25
    protected $conversion = null;
26
27
    public function getUrl(): string
28
    {
29
        if (!$this->media->hasFile()) {
30
            return $this->media->getCollection()->getDefaultMediaUrl();
31
        }
32
33
        return $this->getDisk()->getUrl($this->getPath());
34
    }
35
36
    public function getPath(): string
37
    {
38
        $convestion = $this->conversion instanceof Conversion ? $this->conversion->getName() : null;
0 ignored issues
show
introduced by
$this->conversion is always a sub-type of ByTIC\MediaLibrary\Conversions\Conversion.
Loading history...
39
        return $this->media->getPath($convestion);
40
    }
41
42
    public function setMedia(Media $media): UrlGeneratorInterface
43
    {
44
        $this->media = $media;
45
46
        return $this;
47
    }
48
49
    public function setConversion(Conversion $conversion): UrlGeneratorInterface
50
    {
51
        $this->conversion = $conversion;
52
53
        return $this;
54
    }
55
56
    public function setPathGenerator(AbstractPathGenerator $pathGenerator): UrlGeneratorInterface
57
    {
58
        $this->pathGenerator = $pathGenerator;
0 ignored issues
show
Bug Best Practice introduced by
The property pathGenerator does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
59
60
        return $this;
61
    }
62
63
//    protected function getDiskName(): string
64
//    {
65
//        return $this->conversion === null
66
//            ? $this->media->disk
67
//            : $this->media->conversions_disk;
68
//    }
69
70
    protected function getDisk(): FilesystemInterface
71
    {
72
//        return app('filesystem')->disk($this->getDiskName());
73
        return $this->media->getFile()->getFilesystem();
74
    }
75
}