Translations::trans()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 4
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the WPFoundation library.
5
 *
6
 * Copyright (c) 2015-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\WPFoundation\Configuration\Translations;
13
14
/**
15
 * Class of translations that implements the interface with
16
 * "trans" method. This class is strongly coupled to the WPML.
17
 *
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class Translations implements TranslationsInterface
21
{
22
    /**
23
     * Domain translation name.
24
     *
25
     * This variable avoids the use of global
26
     * constants and it's extensible in an easy way.
27
     *
28
     * @var string
29
     */
30
    protected static $domain = 'WP Foundation default domain';
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public static function trans($key)
36
    {
37
        if (false === function_exists('icl_t') || false === function_exists('icl_register_string')) {
38
            return $key;
39
        }
40
41
        if (empty(icl_t(self::domain(), $key))) {
42
            icl_register_string(self::domain(), $key, $key);
0 ignored issues
show
Unused Code introduced by
The call to icl_register_string() has too many arguments starting with self::domain().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the function icl_register_string() seems unnecessary as the function has no side-effects.
Loading history...
43
44
            return $key;
45
        }
46
47
        return icl_t(self::domain(), $key);
48
    }
49
50
    /**
51
     * Returns the domain defined into TRANSLATION_DOMAIN global
52
     * const or otherwise the value of domain static variable.
53
     *
54
     * @return string
55
     */
56
    private static function domain()
57
    {
58
        return defined('TRANSLATION_DOMAIN') ? TRANSLATION_DOMAIN : self::$domain;
59
    }
60
}
61