Passed
Push — master ( b91050...6fb96f )
by Jens
02:59
created

LinkService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 42
rs 10
wmc 6
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInstance() 0 7 2
A get() 0 13 3
1
<?php
2
/**
3
 * Created by jensk on 12-10-2017.
4
 */
5
6
namespace CloudControl\Cms\services;
7
8
9
use CloudControl\Cms\cc\Request;
10
use CloudControl\Cms\components\LanguageComponent;
11
12
class LinkService
13
{
14
    private static $instance;
15
16
    /**
17
     * LinkService constructor.
18
     */
19
    protected function __construct()
20
    {
21
    }
22
23
    /**
24
     * @return LinkService
25
     */
26
    public static function getInstance()
27
    {
28
        if (!self::$instance instanceof LinkService) {
29
            self::$instance = new LinkService();
30
        }
31
        return self::$instance;
32
    }
33
34
    /**
35
     * Get the (language aware) link to a relative path
36
     *
37
     * @param $relativePath
38
     * @return string
39
     */
40
    public static function get($relativePath)
41
    {
42
        if (isset($_SESSION[LanguageComponent::SESSION_PARAMETER_LANGUAGE_COMPONENT][LanguageComponent::SESSION_PARAMETER_LANGUAGE])) {
43
            $language = $_SESSION[LanguageComponent::SESSION_PARAMETER_LANGUAGE_COMPONENT][LanguageComponent::SESSION_PARAMETER_LANGUAGE];
44
            if ($language == LanguageComponent::$DEFAULT_LANGUAGE) {
45
                return Request::$subfolders . $relativePath;
46
            } else {
47
                return Request::$subfolders . $language . '/' . $relativePath;
48
            }
49
        } else {
50
            return Request::$subfolders . $relativePath;
51
        }
52
    }
53
}