Passed
Push — master ( 420f6f...43b03b )
by Peter
02:45
created

Routes::getCacheUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 21
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Config;
6
7
use AbterPhp\Framework\Constant\Env;
8
use Opulence\Environments\Environment;
9
10
class Routes
11
{
12
    /** @var string|null */
13
    protected static $mediaUrl;
14
15
    /** @var string|null */
16
    protected static $cacheUrl;
17
18
    /**
19
     * @param string $mediaUrl
20
     */
21
    public static function setMediaUrl(string $mediaUrl): void
22
    {
23
        static::$mediaUrl = $mediaUrl;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public static function getMediaUrl(): string
30
    {
31
        if (null !== static::$mediaUrl) {
32
            return static::$mediaUrl;
33
        }
34
35
        static::$mediaUrl = (string)Environment::getVar(Env::MEDIA_BASE_URL);
36
37
        return static::$mediaUrl;
38
    }
39
40
    /**
41
     * @param string $cacheUrl
42
     */
43
    public static function setCacheUrl(string $cacheUrl): void
44
    {
45
        static::$cacheUrl = $cacheUrl;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public static function getCacheUrl(): string
52
    {
53
        if (null !== static::$cacheUrl) {
54
            return static::$cacheUrl;
55
        }
56
57
        $cachePath = Environment::getVar(Env::CACHE_BASE_PATH, '');
58
        if (!$cachePath) {
59
            return '';
60
        }
61
62
        $cacheUrl = sprintf(
63
            '%s%s%s',
64
            rtrim(static::getMediaUrl(), DIRECTORY_SEPARATOR),
65
            DIRECTORY_SEPARATOR,
66
            ltrim($cachePath, DIRECTORY_SEPARATOR)
67
        );
68
69
        static::$cacheUrl = (string)$cacheUrl;
70
71
        return static::$cacheUrl;
72
    }
73
}
74