Passed
Push — main ( 3c0f49...2c259b )
by Peter
04:10
created

Routes::setAssetsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
    public const ASSETS_PATH = '/:path';
13
14
    /** @var string|null */
15
    protected ?string $mediaUrl = null;
16
17
    /** @var string|null */
18
    protected ?string $cacheUrl = null;
19
20
    /** @var string|null */
21
    protected ?string $assetsPath = null;
22
23
    /**
24
     * @param string $mediaUrl
25
     */
26
    public function setMediaUrl(string $mediaUrl): void
27
    {
28
        $this->mediaUrl = $mediaUrl;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getMediaUrl(): string
35
    {
36
        if (null !== $this->mediaUrl) {
37
            return $this->mediaUrl;
38
        }
39
40
        $this->mediaUrl = (string)Environment::getVar(Env::MEDIA_BASE_URL);
41
42
        return $this->mediaUrl;
43
    }
44
45
    /**
46
     * @param string $cacheUrl
47
     */
48
    public function setCacheUrl(string $cacheUrl): void
49
    {
50
        $this->cacheUrl = $cacheUrl;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getCacheUrl(): string
57
    {
58
        if (null !== $this->cacheUrl) {
59
            return $this->cacheUrl;
60
        }
61
62
        $cachePath = Environment::getVar(Env::CACHE_BASE_PATH, '');
63
        if (!$cachePath) {
64
            return '';
65
        }
66
67
        $this->cacheUrl = sprintf(
68
            '%s%s%s',
69
            rtrim(static::getMediaUrl(), DIRECTORY_SEPARATOR),
0 ignored issues
show
Bug Best Practice introduced by
The method AbterPhp\Framework\Config\Routes::getMediaUrl() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

69
            rtrim(static::/** @scrutinizer ignore-call */ getMediaUrl(), DIRECTORY_SEPARATOR),
Loading history...
70
            DIRECTORY_SEPARATOR,
71
            ltrim($cachePath, DIRECTORY_SEPARATOR)
72
        );
73
74
        return $this->cacheUrl;
75
    }
76
77
    /**
78
     * @param string $assetsPath
79
     */
80
    public function setAssetsPath(string $assetsPath): void
81
    {
82
        $this->assetsPath = $assetsPath;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getAssetsPath(): string
89
    {
90
        if (null !== $this->assetsPath) {
91
            return $this->assetsPath;
92
        }
93
94
        $basePath = Environment::getVar(Env::CACHE_BASE_PATH, '');
95
        if (!$basePath) {
96
            return '';
97
        }
98
99
        $this->assetsPath = sprintf('%s%s', $basePath, static::ASSETS_PATH);
100
101
        return $this->assetsPath;
102
    }
103
}
104