Completed
Pull Request — master (#14)
by Gorka
12:44 queued 10:15
created

Translator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A trans() 0 14 4
A domain() 0 4 2
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
declare(strict_types=1);
13
14
namespace LIN3S\WPFoundation;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
final class Translator
20
{
21
    private const DOMAIN = 'WP Foundation default domain';
22
23
    public static function trans(string $key) : string
24
    {
25
        if (false === function_exists('icl_t') || false === function_exists('icl_register_string')) {
26
            return $key;
27
        }
28
29
        if (empty(icl_t(self::domain(), $key))) {
30
            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...
31
32
            return $key;
33
        }
34
35
        return icl_t(self::domain(), $key);
36
    }
37
38
    private static function domain() : string
39
    {
40
        return defined('TRANSLATION_DOMAIN') ? TRANSLATION_DOMAIN : self::DOMAIN;
41
    }
42
}
43