Languages   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguages() 0 32 2
A getLanguage() 0 8 2
1
<?php
2
3
namespace Asymptix\localization;
4
5
/**
6
 * Languages functionality class.
7
 *
8
 * @category Asymptix PHP Framework
9
 * @author Dmytro Zarezenko <[email protected]>
10
 * @copyright (c) 2009 - 2015, Dmytro Zarezenko
11
 *
12
 * @git https://github.com/Asymptix/Framework
13
 * @license http://opensource.org/licenses/MIT
14
 */
15
class Languages {
16
17
    /**
18
     * Stores all needed languages and titles in different languages.
19
     *
20
     * @var array
21
     */
22
    public static $langs = null;
23
24
    public static function getLanguages() {
25
        if (is_null(self::$langs)) {
26
            self::$langs = [
27
                'en' => new Language('en', [
28
                    'en' => "English",
29
                    'de' => "Englisch",
30
                    'ru' => "Английский",
31
                    'uk' => "Англійська"
32
                ], 'gb'),
33
                'de' => new Language('de', [
34
                    'en' => "German",
35
                    'de' => "Deutsch",
36
                    'ru' => "Немецкий",
37
                    'uk' => "Німецька"
38
                ], 'de'),
39
                'ru' => new Language('ru', [
40
                    'en' => "Russian",
41
                    'de' => "Rusisch",
42
                    'ru' => "Русский",
43
                    'uk' => "Російська"
44
                ], 'ru'),
45
                'uk' => new Language('uk', [
46
                    'en' => "Ukrainian",
47
                    'de' => "Ukrainisch",
48
                    'ru' => "Украинский",
49
                    'uk' => "Українська"
50
                ], 'ua'),
51
            ];
52
        }
53
54
        return self::$langs;
55
    }
56
57
    /**
58
     * Returns Language object by it's ISO code.
59
     *
60
     * @param string $code ISO language code.
61
     * @return Language
62
     */
63
    public static function getLanguage($code) {
64
        $langs = self::getLanguages();
65
        if (isset($langs[$code])) {
66
            return $langs[$code];
67
        } else {
68
            return $langs['en'];
69
        }
70
    }
71
72
}
73