Application::getPrefixUrl()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 4
nop 2
1
<?php
2
3
namespace Core;
4
5
class Application
6
{
7
    private static $config = [];
8
9
    public static function setConfig(array $config)
10
    {
11
        self::$config = $config;
12
    }
13
14
    /**
15
     * Return url path with site url
16
     * @param  string $url sub url
17
     * @return string
18
     */
19
    public static function getUrl($url = '')
20
    {
21
        return self::getPrefixUrl(self::$config['url'], $url);
22
    }
23
24
    public static function getPublicUrl($url = '')
25
    {
26
        return self::getPrefixUrl(self::$config['publicPath'], $url);
27
    }
28
29
    private static function getPrefixUrl($prefix, $path)
30
    {
31
        $prefix = $prefix . (substr($prefix, -1) !== '/' ? '/' : '');
32
        $path = substr($path, 0, 1) === '/' ? substr($path, 1) : $path;
33
34
        return $prefix . $path;
35
    }
36
}
37