Completed
Push — 2.0 ( 9e2b8d )
by Nicolas
03:40
created

MediaPath::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php namespace Modules\Media\ValueObjects;
2
3
use Modules\Media\UrlResolvers\BaseUrlResolver;
4
5
class MediaPath
6
{
7
    /**
8
     * @var string
9
     */
10
    private $path;
11
12
    public function __construct($path)
13
    {
14
        if (! is_string($path)) {
15
            throw new \InvalidArgumentException('The path must be a string');
16
        }
17
        $this->path = $path;
18
    }
19
20
    /**
21
     * Get the URL depending on configured disk
22
     * @return string
23
     */
24
    public function getUrl()
25
    {
26
        return (new BaseUrlResolver())->resolve($this->path);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getRelativeUrl()
33
    {
34
        return $this->path;
35
    }
36
37
    public function __toString()
38
    {
39
        try {
40
            return $this->getUrl();
41
        } catch (\Exception $e) {
42
            return '';
43
        }
44
    }
45
}
46