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

Routes   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 92
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setCacheUrl() 0 3 1
A setMediaUrl() 0 3 1
A getMediaUrl() 0 9 2
A getCacheUrl() 0 19 3
A getAssetsPath() 0 14 3
A setAssetsPath() 0 3 1
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