Completed
Pull Request — master (#35)
by Michal
06:39
created

Translator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 23 3
A gettext() 0 5 1
1
<?php
2
3
/**
4
 * Defines the localization helper infrastructure of the library.
5
 *
6
 * @package SqlParser
7
 */
8
namespace SqlParser;
9
10
use MoTranslator;
11
12
class Translator
13
{
14
    /**
15
     * The MoTranslator loader object.
16
     *
17
     * @var MoTranslator\Loader
18
     */
19
    private static $loader;
20
21
    /**
22
     * The MoTranslator translator object.
23
     *
24
     * @var MoTranslator\Translator
25
     */
26
    private static $translator;
27
28
    /**
29
     * Loads transator
30
     *
31
     * @return void
32
     */
33 47
    public static function load()
34
    {
35 47
        if (is_null(self::$loader)) {
36
            // Create loader object
37 4
            self::$loader = new MoTranslator\Loader();
38
39
            // Set locale
40 4
            self::$loader->setlocale(
41 4
                self::$loader->detectlocale()
0 ignored issues
show
Bug introduced by
The method detectlocale() does not seem to exist on object<MoTranslator\Loader>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42 4
            );
43
44
            // Set default text domain
45 4
            self::$loader->textdomain('sqlparser');
46
47
            // Set path where to look for a domain
48 4
            self::$loader->bindtextdomain('sqlparser', __DIR__ . '/../locale/');
49 4
        }
50
51 47
        if (is_null(self::$translator)) {
52
            // Get translator
53 4
            self::$translator = self::$loader->get_translator();
54 4
        }
55 47
    }
56
57
    /**
58
     * Translates a string
59
     *
60
     * @param string $msgid String to be translated
61
     *
62
     * @return string translated string (or original, if not found)
63
     */
64 47
    public static function gettext($msgid)
65
    {
66 47
        self::load();
67 47
        return self::$translator->gettext($msgid);
68
    }
69
}
70