Passed
Push — master ( 7f25ec...97f7f8 )
by Joël
02:26
created

gettext_helper.php ➔ __()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
// @codeCoverageIgnoreStart
3
defined('BASEPATH') || exit('No direct script access allowed');
4
// @codeCoverageIgnoreEnd
5
6
/**
7
 * CodeIgniter Gettext Helpers
8
 *
9
 * @package        CodeIgniter
10
 * @subpackage     Helpers
11
 * @category       Gettext
12
 * @author         Joël Gaujard <[email protected]>
13
 */
14
15
if (!function_exists('__')) {
16
    /**
17
     * @param string $expression
18
     * @return string
19
     */
20
    function __($expression, $domain = NULL)
21
    {
22 6
        if (!empty($domain)) {
23 2
            (new \Gettext())->changeDomain($domain);
24 2
            return (dgettext($domain, $expression));
25
        }
26
27 4
        return (gettext($expression));
28
    }
29
}
30
31
if (!function_exists('_e')) {
32
    /**
33
     * @param string $expression
34
     */
35
    function _e($expression, $domain = NULL)
36
    {
37 3
        echo (__($expression, $domain));
38 3
    }
39
}
40
41
if (!function_exists('_n')) {
42
    /**
43
     * @param $expression_singular
44
     * @param $expression_plural
45
     * @param $number
46
     * @return string
47
     */
48
    function _n($expression_singular, $expression_plural, $number, $domain = NULL)
49
    {
50 3
        $number = (int) $number;
51
52 3
        if (!empty($domain)) {
53 1
            (new \Gettext())->changeDomain($domain);
54 1
            return (dngettext($domain, $expression_singular, $expression_plural, $number));
55
        }
56
57 2
        return (ngettext($expression_singular, $expression_plural, $number));
58
    }
59
}